A9242 | Vasya and Robot
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya has $n$ items lying in a line. The items are consecutively numbered by numbers from $1$ to $n$ in such a way that the leftmost item has number $1$ , the rightmost item has number $n$ . Each item has a weight, the $i$ -th item weights $w_{i}$ kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:
1. Take the leftmost item with the left hand and spend $w_{i}·l$ energy units ( $w_{i}$ is a weight of the leftmost item, $l$ is some parameter). If the previous action was the same (left-hand), then the robot spends extra $Q_{l}$ energy units;
2. Take the rightmost item with the right hand and spend $w_{j}·r$ energy units ( $w_{j}$ is a weight of the rightmost item, $r$ is some parameter). If the previous action was the same (right-hand), then the robot spends extra $Q_{r}$ energy units;
Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:
1. Take the leftmost item with the left hand and spend $w_{i}·l$ energy units ( $w_{i}$ is a weight of the leftmost item, $l$ is some parameter). If the previous action was the same (left-hand), then the robot spends extra $Q_{l}$ energy units;
2. Take the rightmost item with the right hand and spend $w_{j}·r$ energy units ( $w_{j}$ is a weight of the rightmost item, $r$ is some parameter). If the previous action was the same (right-hand), then the robot spends extra $Q_{r}$ energy units;
Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
输入格式
The first line contains five integers $n,l,r,Q_{l},Q_{r}$ $(1<=n<=10^{5};1<=l,r<=100;1<=Q_{l},Q_{r}<=10^{4})$ .
The second line contains $n$ integers $w_{1},w_{2},...,w_{n}$ $(1<=w_{i}<=100)$ .
The second line contains $n$ integers $w_{1},w_{2},...,w_{n}$ $(1<=w_{i}<=100)$ .
输出格式
In the single line print a single number — the answer to the problem.
输入输出样例
输入 #1
3 4 4 19 1 42 3 99
输出 #1
576
输入 #2
4 7 2 3 9 1 2 3 4
输出 #2
34
Consider the first sample. As $l=r$ , we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends $4·42+4·99+4·3=576$ energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends $(2·4)+(7·1)+(2·3)+(2·2+9)=34$ energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends $(2·4)+(7·1)+(2·3)+(2·2+9)=34$ energy units.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted