luogu P3745 [六省联考2017]期末考试
题面传送门
完全没有紫题难度吧qwq
看到时间这么小考虑枚举最后的结束时间,那么维护两个前缀和分别表示前后能要换的天数然后分类讨论即可。
但是还要开ull是没有想到的。
时间复杂度\(O(n)\)
code:
#include<cstdio>
#define ull unsigned long long
#define N 100039
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
int n,m,x; ull A,B,C,s[N],q[N],f[N],g[N],ans=1e19,tot,now,cnt1,cnt2;
int main(){
freopen("1.in","r",stdin);
register int i;
scanf("%llu%llu%llu%d%d",&A,&B,&C,&n,&m);
for(i=1;i<=n;i++) scanf("%d",&x),f[x+1]++;
for(i=1;i<=m;i++) scanf("%d",&x),s[x-1]++,q[x+1]++;
for(i=1;i<N;i++)f[i]+=f[i-1],q[i]+=q[i-1];
for(i=N-2;~i;i--)s[i]+=s[i+1];
for(i=0;i<N;i++) cnt1+=s[i];
for(i=0;i<N;i++){
now+=f[i];cnt2+=q[i];tot=now*C;
if(A>B) tot+=B*cnt1;
else{
if(cnt2>cnt1) tot+=A*cnt1;
else tot+=A*cnt2+(cnt1-cnt2)*B;
}
cnt1-=s[i];ans=min(ans,tot);
}
printf("%llu\n",ans);
}

浙公网安备 33010602011771号