PROSUM...TLE

I have written the following code but am getting a TLE.Could someone please tell me how to decrease the time complexity.Thanks in advance.

Following is the link of the code : xtRtMI - Online C++ Compiler & Debugging Tool - Ideone.com

Next time, please ask a question on editorial page - PROSUM - Editorial - editorial - CodeChef Discuss

Your code complexity is O(n^2)

for(i=0;i<(n-1);i++)
    for(j=(i+1);j<n;j++)
        ...

@betlista I know that the code complexity is O(n^2) but I was asking for a method to decrease it so that I do not get a TLE.

read the editorial :wink:

You have to do it in O(n)