SOL:我们枚举最晚的一门学科在什么时候出成绩,统计答案即可。
我们考虑两种方法,搞一搞就好了。
#include<bits/stdc++.h> #define N 100005 #define LL long long using namespace std; int pa,pb,pc,n,m,a[N],b[N],l,r; LL s,cqhsb,ans=1e15,le,sum1,sum2; signed main(){ freopen("exam.in","r",stdin); freopen("exam.out","w",stdout); scanf("%d%d%d",&pa,&pb,&pc); pa=min(pa,pb); scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) scanf("%d",a+i);sort(a+1,a+n+1); for (int i=1;i<=m;i++) scanf("%d",b+i);sort(b+1,b+m+1); for (int i=1;i<=m;i++) sum2+=b[i]; sum2+=m; for (int i=0;i<=a[n];i++){ while (a[l+1]<i) l++; s+=l;sum2-=m-r; while (b[r+1]==i) r++,sum1+=b[r]; if (pa<pb){ le=1ll*i*r-sum1; if (le>=sum2) cqhsb=sum2*pa+1ll*s*pc; else cqhsb=le*pa+(sum2-le)*pb+1ll*s*pc;} else cqhsb=sum2*pb+1ll*s*pc; if (cqhsb<ans) ans=cqhsb; } printf("%lld",ans); return 0; }