problem in maximize the sum in problem for march challenge 2016

I tried to solve the problem "Maximize the sum " from march long challenge. My solution is passing the 2 sub-tasks but it is failing to achieve third sub-task. can anyone figure out what is bug in my code.

Link to my solution: https://www.codechef.com/viewsolution/9699718

1 Like

Your solution is failing for the third subtask because of overflow. You have to use long instead of integer. Here is your modified solution which gives AC. Hope this helps.

thanks ash_code