其他分享
首页 > 其他分享> > ABC 263.D - Left Right Operation(思维)

ABC 263.D - Left Right Operation(思维)

作者:互联网

https://atcoder.jp/contests/abc263/tasks/abc263_d

给我们一个长度为n的序列
只需执行一次以下连续操作:

选择一个整数x,将前x个数全部换成L
选择一个整数y,将后y个数全部换成R

问我们能得到的最小总和是多少?
Sample Input 1 
5 4 3
5 5 0 6 3
Sample Output 1 
14

Sample Input 2 
4 10 10
1 2 3 4
Sample Output 2 
10

Sample Input 3 
10 -5 -3
9 -6 10 -1 2 10 -1 7 -15 5
Sample Output 3 
-58
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=200200;
LL a[N];
LL f[N],g[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL n,L,R;
    cin>>n>>L>>R;
    for(LL i=1;i<=n;i++)
        cin>>a[i];
    f[0]=0;
    for(LL i=1;i<=n;i++)
        f[i]=min(f[i-1]+a[i],i*L);
    /*for(int i=0;i<=n;i++)
        cout<<f[i]<<" ";
    cout<<endl;*/
    g[n+1]=0;
    for(LL i=n;i>=1;i--)
        g[i]=min(g[i+1]+a[i],(n-i+1)*R);
    /*for(int i=0;i<=n;i++)
        cout<<g[i]<<" ";
    cout<<endl;*/
    LL minn=1e18;
    for(LL i=0;i<=n;i++)
    {
        minn=min(minn,f[i]+g[i+1]);
    }
    cout<<minn<<endl;
    return 0;
}

标签:10,ABC,Sample,int,LL,263,Right,Input,include
来源: https://www.cnblogs.com/Vivian-0918/p/16558278.html