A10037 | Bear and Bowling
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 . 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?
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 . 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?
输入格式
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.
The second line contains $n$ space-separated integers $a_{1},a_{2},...,a_{n}$ ( $|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$ 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$ .
In second sample Limak should cancel roll with score $-50$ . Total score is $1·(-10)+2·20+3·(-30)+4·40+5·60=400$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted