2705.Bear and Bowling

Time Limit: 1s Memory Limit: 256MB

Limak is an old brown bear. He often goes bowling with his friends. Today he feels really good and tries to beat his own record!

For rolling a ball one gets a score - an integer (maybe negative) number of points. Score for i-th roll is multiplied by i and scores are summed up. So, for k rolls with scores s1,s2,...,sk, total score is 2705_1.png. Total score is 0 if there were no rolls.

Limak made n rolls and got score ai for i-th of them. He wants to maximize his total score and he came up with an interesting idea. He will cancel some rolls, saying that something distracted him or there was a strong wind.

Limak is able to cancel any number of rolls, maybe even all or none of them. Total score is calculated as if there were only non-canceled rolls. Look at the sample tests for clarification. What maximum total score can Limak get?

Input Format(From the terminal/stdin)

The first line contains single integer n (1 \le n \le 105).

The second line contains n space-separated integers a1,a2,...,an (|ai| \le 107) - scores for Limak's rolls.

Output Format(To the terminal/stdout)

Print the maximum possible total score after choosing rolls to cancel.

Sample Input 1

Copy
5
-2 -8 0 5 -3
 \n
  ·  · · ·  \n

Sample Output 1

Copy
13
  \n

Sample Input 2

Copy
6
-10 20 -30 40 -50 60
 \n
   ·  ·   ·  ·   ·  \n

Sample Output 2

Copy
400
   \n

Hints

In first sample Limak should cancel rolls with scores -8 and -3. Then he is left with three rolls with scores -2,0,5. Total score is 1 \cdot (-2)+2 \cdot 0+3 \cdot 5=13.

In second sample Limak should cancel roll with score -50. Total score is 1 \cdot (-10)+2 \cdot 20+3 \cdot (-30)+4 \cdot 40+5 \cdot 60=400.

Submit

请先 登录

© 2025 FAQs