Set i and j and check if array from i to j - 1 gives sum <= x
for ( int i = 0 ; i < presum . size ( ) ; i ++ ) { for ( int j = i + 1 ; j < presum . size ( ) ; j ++ ) { int arr1_sum = ( presum [ i ] + ( total_sum - presum [ j ] ) ) ; if ( ( arr1_sum <= x ) && ( total_sum - arr1_sum ) <= x ) return true ; } } return false ; }