Vasya and Robot CodeForces - 354A
原题链接
考察:枚举,思维
思路:
不论怎么取,都存在一个间隔点:左边的都是左手拿的,右边的都是右手拿的,枚举间断点,可以发现根据取的个数不同,由于贪心是尽可能间隔取,然后再计算连续的附加值.
Code
#include <iostream>
#include <cstring>
using namespace std;
const int N = 100010,INF = 0x3f3f3f3f;
int n,l,r,Ql,Qr,w[N],LC[N],RC[N];
void solve()
{
int res = INF;
for(int i=0;i<=n;i++)//左手拿i个
{
int j = n-i,cost = 0;
if(abs(i-j)<=1) cost+=LC[i]+RC[n]-RC[i];
else if(i>j)
{
int cnt = i-j-1;
cost+=RC[n]-RC[i]+LC[i]+Ql*cnt;
}else{
int cnt = j-i-1;
cost+=LC[i]+RC[n]-RC[i]+Qr*cnt;
}
res = min(cost,res);
}
printf("%d\n",res);
}
int main()
{
scanf("%d%d%d%d%d",&n,&l,&r,&Ql,&Qr);
for(int i=1;i<=n;i++)
{
scanf("%d",&w[i]);
LC[i] = LC[i-1]+l*w[i];
RC[i] = RC[i-1]+r*w[i];
}
solve();
return 0;
}