Select the maximum j by which a non negative prefix sum subsequence can be obtained
for j in range ( N + 1 ) : NEW_LINE INDENT if ( dp [ N - 1 ] [ j ] >= 0 ) : NEW_LINE INDENT ans = j NEW_LINE DEDENT DEDENT