Hello guys,

I was solving the problem MAXI from SPOJ but couldn’t figure out a solution. Any insights would be much appreciated.

Thanks

By seeing your post i have gone through problem maxi…i have solved it in O(n^2).But some comments claimed that they solved this in O(n).I can not figure out how they did it in O(n) but i there is solution in O(n) and it takes 0.0 s,mine takes 0.13 s.But for O(n^2) its dynamic programming if u see it carefully.

Hope this helps.

Thanks for the reply. It would be great if you can give a link to your code!

Thank you

Well I too had a O(n^{2}) algorithm in back of my mind. I thought it may not pass the time limit of 0.2 secs as n<=10^{4}.

Can you explain how will it pass the time limit?

Because its asymptotic complexity not exact complexity :).

Inner loops upper bound keeps up decrements by 1 each time you run the loop.

So it n only at first iteration there after it will keep decrements and reduce the time.