zoukankan      html  css  js  c++  java
  • luogu P3745 [六省联考2017]期末考试

    luogu

    因为(C)对答案的贡献只和(max b_i)有关,所以我们枚举这个值(z),然后把所有(>z)(b)全部变成(z),这里如果(A<B),那么还可以把一些(<z)(b)(z)方向变,这样就可以使用一些(A)操作代替(B)操作,(Age 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
    ",ans);
    	return 0;
    }
    
  • 相关阅读:
    React Native 架构演进
    React Native 架构一览
    React Native 在 Airbnb 的起起落落
    React Native简史
    图解云服务模型的演进
    伯克利研究员们眼中的Cloud Computing
    彻底理解 IaaS、PaaS、SaaS
    JS更随机的随机数
    JS自动化
    fingerprint2 计算浏览器指纹分析
  • 原文地址:https://www.cnblogs.com/smyjr/p/12912418.html
Copyright © 2011-2022 走看看