CF660F.Bear and Bowling 4

普及/提高-

通过率: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 the 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} , the total score is . The total score is 00 if there were no rolls.

Limak made nn rolls and got score aia_{i} for the ii -th of them. He wants to maximize his total score and he came up with an interesting idea. He can say that some first rolls were only a warm-up, and that he wasn't focused during the last rolls. More formally, he can cancel any prefix and any suffix of the sequence a1,a2,...,ana_{1},a_{2},...,a_{n} . It is allowed to cancel all rolls, or to cancel none of them.

The total score is calculated as if there were only non-canceled rolls. So, the first non-canceled roll has score multiplied by 11 , the second one has score multiplied by 22 , and so on, till the last non-canceled roll.

What maximum total score can Limak get?

输入格式

The first line contains a single integer nn ( 1<=n<=21051<=n<=2·10^{5} ) — the total number of rolls made by Limak.

The second line contains nn 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 cancelling rolls.

输入输出样例

  • 输入#1

    6
    5 -1000 1 -3 7 -8
    

    输出#1

    16
    
  • 输入#2

    5
    1000 1000 1001 1000 1000
    

    输出#2

    15003
    
  • 输入#3

    3
    -60 -70 -80
    

    输出#3

    0
    

说明/提示

In the first sample test, Limak should cancel the first two rolls, and one last roll. He will be left with rolls 1,3,71,-3,7 what gives him the total score 11+2(3)+37=16+21=161·1+2·(-3)+3·7=1-6+21=16 .

首页