Codeforce div 2 ques 2

Problem link : https://codeforces.com/contest/1285/problem/B
My solution : https://ideone.com/6tl5Bp
During contest I tried as many test case as it was possible for me but it was giving expected answer, can anyone suggest the test case where it failed.

It is said in the problem that we cant take L and R as 1 and N
But you are considering that also i think

1
6
1 3 4 -1 4 5
Your solution will fail on this teat case. Actually, according to your solution answer should be yes only when all values are positive or sum > maximum sub array sum. But in above case all numbers are not positive and sum == maximum sub array sum, but you can not take complete array in finding maximum sub array sum.

1 Like

calaculate max subarray sums for 1) excluding 1st number 2) excluding last number…
then if complete array sum is strictly greater than both of max subbarray sums …then print “YES”.
Otherwise, "NO
You can calculate max subarray sum in O(n) using Kadane algorithm.

Yeah, I realised my mistake actually during contest I thought that f=0 will take care of that case which is weird even for me now