vasya (CF_#206_A)

来源:互联网 发布:人工智能算法 编辑:程序博客网 时间:2024/04/19 19:12

题意:给定一个数字串,在串的最左边和最右边来回地取数,

          n,l,r,Ql,Qr分别代表数据长度,取左边时乘以的权值,

          取右边时乘以的权值,连续两次取左边加上的额外的值

         连续取右边时加上的额外的值。

求:使取出的总值最小是多少。


做法:直接假设前i个数是用左边法则取的,其余为右边法则取的。

           一个一个地枚举就可以了。


感想:当时晚上做时一下没有想上来就杯具了。


#include<iostream>using namespace std;#define N 100001int n;int go[N];long long sum[N];long long ans;int main(){int i,j,k;intl,r,Ql,Qr;cin>>n>>l>>r>>Ql>>Qr;for (i=1;i<=n;i++)cin>>go[i];sum[0]=0;for (i=1;i<=n;i++)sum[i]=sum[i-1]+go[i];long long cur,temp1,temp2;ans=(n-1)*Qr+sum[n]*r;for (i=1;i<=n;i++){cur=(sum[n]-sum[i])*r+sum[i]*l;j=n-i;if (i-j > 1)cur+=(i-j-1)*Ql;if (j-i > 1)cur+=(j-i-1)*Qr;ans=min(ans,cur);}cout<<ans<<endl;return 0;}


A. 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:

  1. 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;
  2. 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.

Sample test(s)
input
3 4 4 19 142 3 99
output
576
input
4 7 2 3 91 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.




http://codeforces.com/contest/354/problem/A