CF573E.Bear and Bowling

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 ii -th roll is multiplied by ii and scores are summed up. So, for kk rolls with scores s1,s2,...,sks_{1},s_{2},...,s_{k} , total score is . Total score is 00 if there were no rolls.

Limak made nn rolls and got score aia_{i} for ii -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?

输入格式

The first line contains single integer nn ( 1<=n<=1051<=n<=10^{5} ).

The second line contains nn space-separated integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( ai<=107)|a_{i}|<=10^{7}) - scores for Limak's rolls.

输出格式

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

输入输出样例

  • 输入#1

    5
    -2 -8 0 5 -3
    

    输出#1

    13
    
  • 输入#2

    6
    -10 20 -30 40 -50 60
    

    输出#2

    400
    

说明/提示

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

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

首页