CF660F.Bear and Bowling 4
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
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 i-th roll is multiplied by i and scores are summed up. So, for k rolls with scores _s_1, _s_2, ..., s__k, the total score is
. The total score is 0 if there were no rolls.
Limak made n rolls and got score a__i for the i-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 _a_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 1, the second one has score multiplied by 2, and so on, till the last non-canceled roll.
What maximum total score can Limak get?
Limak 是一只年迈的棕熊。他经常和朋友们一起去打保龄球。今天他感觉特别好,打算打破自己的纪录!
每次投球会得到一个分数——一个整数(可能为负)分。第 i 次投球的分数乘以 i,然后将所有乘积相加,即为总分。因此,对于 k 次投球,其分数分别为 s1, s2, …, sk,总分为
。
若未进行任何投球,则总分为 0。
Limak 共进行了 n 次投球,第 i 次的得分为 ai。他希望最大化自己的总分,并提出了一个有趣的想法:他可以声称最开始的若干次投球只是热身,而最后的若干次投球时自己又不够专注。更准确地说,他可以取消序列 a1, a2, …, an 的任意一个前缀和任意一个后缀(即保留中间一段连续子序列)。允许取消全部投球,也允许不取消任何投球。
总分仅根据未被取消的投球来计算:第一个未被取消的投球得分乘以 1,第二个未被取消的投球得分乘以 2,依此类推,直到最后一个未被取消的投球。
Limak 能获得的最大总分是多少?
输入格式
The first line contains a single integer n (1 ≤ n ≤ 2·105) — the total number of rolls made by Limak.
The second line contains n integers _a_1, _a_2, ..., a__n (|a__i| ≤ 107) — scores for Limak's rolls.
第一行包含一个整数 n(1≤n≤2⋅105)—— Limak 投掷的总次数。
第二行包含 n 个整数 a1,a2,…,an(∣ai∣≤107)—— Limak 每次投掷的得分。
输出格式
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, 7 what gives him the total score 1·1 + 2·( - 3) + 3·7 = 1 - 6 + 21 = 16.
在第一个样例测试中,Limak 应当取消前两次掷骰子以及最后一次掷骰子。他将剩下掷骰子结果:1、 - 3、 7,总得分为 1⋅1+2⋅(−3)+3⋅7=1−6+21=16。
输入解题思路,AI测评打分。不知道怎么写?