ZOJ Summer 2018 1020

#include <deque>

 

 

There is a deque of size n and you want to use it now, but unfortunately it's not empty yet. So, before using it, you're forced to do this boring work: clear it.

Each time you pop the i th number from the left side, you'll get L * wi unhappiness points. Similarly, you'll get R * wi unhappiness points if you take the i th number from the right side.

However, keep taking numbers from one side will make the work more boring. So if the previous operation is the same, you'll get qL or qR extra unhappiness points, depending on the side you take numbers from. L , R , qL and qR are all constant. Now given L , R , qL , qR and the deque, you want to know the minimum unhappiness you can get.

Input

There are multiple test cases. For each test case: the first line contains 5 integers, n , L , R , qL and qR , seperated by a single space. the second line contains n integers, the i th integer is wi (1 ≤ n≤ 100000, 1 ≤ n , L , R , qL , qR, wi ≤ 100)

Output

For each test case, output an integer in a line, indicating your answer.

Sample Input

2 3 4 5 6
1 2
5 1 10 1 100
1 2 3 4 5

Sample Output

11
19

 

根据题意,左右两边可出每次出去都是ql|qr*wi,第二次和上一次出的方向相同的话需要+qr|ql

先求一下前缀和用于方便求n-i项和,

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll inf=1e18;
const int maxn=1e5+100;
int T;
int n,m,l,r,ql,qr;
int sum[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(cin>>n>>l>>r>>ql>>qr)
    {
        memset(sum,0,sizeof sum);
        for(int i=1; i<=n; i++)
        {
            cin>>sum[i];
            sum[i]+=sum[i-1];
        }
        ll ans=inf;
        for(int i=0;i<=n;i++)
        {
            ll cur=sum[i]*l+(sum[n]-sum[i])*r;
            ll del=abs(n-i-i)-1;
            if(del>0)
            {
                if(n-i>i) cur+=del*qr;
                else cur+=del*ql;
            }
            if(cur<ans) ans=cur;
        }
        cout<<ans<<endl;

    }


    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值