MAX is the Maximum value M can take
var dp = Array ( n + 1 ) ; for ( i = 0 ; i < n + 1 ; i ++ ) { dp [ i ] = Array ( MAX ) . fill ( - 1 ) ; } var res ; if ( isPossible ( n , 1 , arr [ 0 ] , M , arr , dp ) == 1 ) { res = true ; } else { res = false ; } document . write ( res ? " " : " " ) ;