luogu P3745 [六省联考2017]期末考试

luogu

因为\(C\)对答案的贡献只和\(\max b_i\)有关,所以我们枚举这个值\(z\),然后把所有\(>z\)\(b\)全部变成\(z\),这里如果\(A<B\),那么还可以把一些\(<z\)\(b\)\(z\)方向变,这样就可以使用一些\(A\)操作代替\(B\)操作,\(A\ge B\)就算了.可以发现从大到小枚举\(z\),\(C\)的贡献和\(A,B\)的贡献是可以实时维护的,然后就完事了

注意C很大可能会爆long long

//看代码应该看得懂
#include<bits/stdc++.h>
#define LL long long
#define db double

using namespace std;
const int N=2e5+10;
const LL sh=1e18;
LL rd()
{
    LL x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
LL c1,c2,c3,na,a1,a2,ans;
int n,m,a[N],b[N];

int main()
{
	c1=rd(),c2=rd(),c3=rd(),n=rd(),m=rd();
	for(int i=1;i<=n;++i) a[i]=rd();
	for(int i=1;i<=m;++i) b[i]=rd();
	sort(a+1,a+n+1),sort(b+1,b+m+1);
	int z=b[m];
	for(int i=1;i<=n;++i) na+=max(z-a[i],0);
	for(int i=1;i<=m;++i) a2+=z-b[i];
	ans=na<=sh/c3?na*c3:sh,--z;
	for(int i=n,j=m;~z;--z)
	{
		while(i&&a[i]>z) --i;
		while(j&&b[j]>z) --j;
		na-=i,a1+=m-j,a2-=j;
		ans=min(ans,(na<=sh/c3?na*c3:sh)+(c1<c2?(c1*min(a1,a2)+c2*max(a1-min(a1,a2),0ll)):(c2*a1)));
	}
	printf("%lld\n",ans);
	return 0;
}
posted @ 2020-05-18 18:57  ✡smy✡  阅读(173)  评论(0编辑  收藏  举报