Help in Maximum special array sum

Link of the problem - https://www.codechef.com/problems/MAXSPSUM