Help needed in MAXSEGM

I am getting WA for my solution https://www.codechef.com/viewsolution/25497531
What’s wrong with my logic?. Please help.
Question link: https://www.codechef.com/problems/MAXSEGM

Hello!
There are two mistakes in your solution.
First the way of initializing vis array! (Go ahead and print the array values after initializing :slight_smile: )
Second, in the if part you are doing s = w[i] which means that you are assigning to s the sum of all the values upto i, which is incorrect. It should store the sum between ptr1 and ptr2. You can fix it by doing something like s += w[i] - (i > 0? w[i-1] : 0).

Hope it helps :smile:

Edit: There is one more mistake. Try to figure that out yourself first. If fails then see the hint!

Hint

Try to find the answer for this
8
0 1 2 3 1 0 2 3
1 1 1 1 1 1 1 1

Yup!! Got it. Thanks::slightly_smiling_face: