您的位置:首页 > 其它

Codeforces Round #206 (Div. 2) C-Vasya and Robot

2016-07-22 00:16 351 查看
C. Vasya and Robot

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

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 wi 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:

Take the leftmost item with the left hand and spend wi · l energy
units (wi 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 Ql energy
units;

Take the rightmost item with the right hand and spend wj · r energy
units (wj 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 Qr 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.

Input

The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).

The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).

Output

In the single line print a single number — the answer to the problem.

Examples

input
3 4 4 19 1
42 3 99


output
576


input
4 7 2 3 9
1 2 3 4


output
34


Note

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.

题意:给你五个数n,l,r,Ql,Qr然后输入n个数,你需要将这n个数全部访问,当你从左边访问时得到l*ai的值,从右边访问时得到r*ai的值,当从左边访问时若上次访问也是左边就要再加上Ql同理右边亦如此,求得到的最小值是多少。

思路:既然全部访问那么可以设从左边访问了k次从右边访问了n-k次那么连续访问的次数就是两者之差。

代码如下:

#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
int a[100005],lefts[100005],rights[100005];
int main()
{
int n,l,r,q1,q2;
scanf("%d%d%d%d%d",&n,&l,&r,&q1,&q2);
memset(lefts,0,sizeof(lefts));
memset(rights,0,sizeof(rights));
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
lefts[i+1]+=(lefts[i]+a[i]);
}
for(int i=n-1;i>=0;i--)
{
rights[n-i]+=(rights[n-i-1]+a[i]);
}
int sum=0,ans=INF;
for(int i=0;i<=n;i++)
{
sum=0;
sum+=((lefts[i]*l)+rights[n-i]*r);
if(i>(n-i)) sum+=((2*i-n-1)*q1);
else if(i<(n-i)) sum+=((n-2*i-1)*q2);
ans=min(ans,sum);
}
printf("%d\n",ans);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  codeforce