洛谷P3745 [六省联考2017]期末考试

传送门

题解

//Achen
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<queue>
#include<cmath>
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long LL;
typedef double db;
using namespace std;
const int N=1e5+7;
LL A,B,C,x,c1[N],c2[N],c3[N],c4[N],c5[N],c6[N],ans,mina=1e18,maxa=-1e18;
int n,m,up=1e5;

template<typename T>void read(T &x)  {
    char ch=getchar(); x=0; T f=1;
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
}

//#define DEBUG
int main() {
#ifdef DEBUG
    freopen("4868期末考试.in","r",stdin);
    freopen("4868期末考试.out","w",stdout);
#endif
    read(A); read(B); read(C);
    read(n); read(m); ans=1e18;
    For(i,1,n) { read(x); c1[x]+=x; c2[x]++; maxa=max(maxa,x); mina=min(mina,x); }
    For(i,1,m) { read(x); c3[x]++; c4[x]++; c5[x]+=x; c6[x]+=x;}
    For(i,1,maxa) c1[i]+=c1[i-1];
    For(i,1,maxa) c2[i]+=c2[i-1];
    For(i,1,up) c3[i]+=c3[i-1],c5[i]+=c5[i-1];
    Rep(i,up,1) c4[i]+=c4[i+1],c6[i]+=c6[i+1];
    For(i,mina,maxa) {
        if(i==37715) {
            int debug=1;
        }
        LL tp=c6[i+1]-c4[i+1]*i-(c3[i]*i-c5[i]);
        if(tp<0) tp=(c6[i+1]-c4[i+1]*i)*A;
        else tp=(c3[i]*i-c5[i])*A+tp*B;
        if(B<A) tp=(c6[i+1]-c4[i+1]*i)*B;
        if(c2[i]*i-c1[i]>=1e18/C) continue;
        ans=min(ans,(c2[i]*i-c1[i])*C+tp);
    }
    printf("%lld
",ans);
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/Achenchen/p/8604394.html