我还第一次见到省选考三分……?
#include<bits/stdc++.h> #define N 200005 using namespace std; typedef long long ll; int n,m,r,t[N],b[N]; ll a,B,c,ans; ll calc(int p){ ll x=0,y=0; for(int i=1;i<=m;i++)if(b[i]<p)x+=p-b[i];else y+=b[i]-p; return a<B?min(x,y)*a+(y-min(x,y))*B:y*B; } inline int read(){ int f=1,x=0;char ch; do{ch=getchar();if(ch==‘-‘)f=-1;}while(ch<‘0‘||ch>‘9‘); do{x=x*10+ch-‘0‘;ch=getchar();}while(ch>=‘0‘&&ch<=‘9‘); return f*x; } int main(){ cin>>a>>B>>c>>n>>m; for(int i=1;i<=n;i++)t[i]=read(); for(int i=1;i<=m;i++)b[i]=read(); sort(b+1,b+m+1);sort(t+1,t+n+1); if(c>=1e16)ans=calc(t[1]); else{ ans=1e16;int l=1,r=N; while(r-l>5){ int mid1=l+(r-l)/3,mid2=r-(r-l)/3; ll c1=calc(mid1),c2=calc(mid2); for(int i=1;i<=n;i++)if(t[i]<mid1)c1+=c*(mid1-t[i]); for(int i=1;i<=n;i++)if(t[i]<mid2)c2+=c*(mid2-t[i]); if (c1<=c2)r=mid2;else l=mid1; } for(int i=l;i<=r;i++){ ll x=calc(i); for(int j=1;j<=n;j++)if(t[j]<i)x+=c*(i-t[j]); ans=min(ans,x); } } cout<<ans<<endl; }
时间: 2024-12-23 12:38:05