Stroring the max candy + 1
int mxcandy = candy [ 0 ] ; for ( int i = 0 ; i < candy . Length ; i ++ ) { if ( mxcandy < candy [ i ] ) { mxcandy = candy [ i ] ; } } int [ ] fr1 = new int [ mxage + 1 ] ; Array . Fill ( fr1 , 0 ) ; int [ ] fr2 = new int [ mxcandy + 1 ] ; Array . Fill ( fr2 , 0 ) ;