Codeforces Round 318 [RussianCodeCup Thanks-Round] (Div. 1)
E
Bear and Bowling
Codeforces
3200
原题
← D→
翻译中…

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 $*s*_{1}, *s*_{2}, ..., *s*_{*k*}$, total score is image. Total score is $0$ if there were no rolls.

翻译中…

Limak made $*n*$ rolls and got score $*a*_{*i*}$ 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

翻译中…

The first line contains single integer $*n*$ ($1 ≤ *n* ≤ 10^{5}$).

翻译中…

The second line contains $*n*$ space-separated integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($|*a*_{*i*}| ≤ 10^{7})$ - scores for Limak's rolls.

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

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·( - 2) + 2·0 + 3·5 = 13$.

翻译中…

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

翻译中…

样例

Input #1
5
-2 -8 0 5 -3
Output #1
13
InputCopy OutputCopy
Input #2
6
-10 20 -30 40 -50 60
Output #2
400
InputCopy OutputCopy
题目信息
题号
573E
时间限制
6 s
内存限制
256 MB
标签
数据结构
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。