About abstract topics:
Divided into two categories: on the degree of unpleasant subjects (A, B) and unhappiness about the degree students (C)
Focus on the thought of the end of half time in all subjects.
For subjects than the end time, if B <= A, then B will try to use to change the time, or change the time with A, can no longer use the A to B and then to change.
As for the students, less than the time limit i is even unpleasant degrees C's.
To do so in all cases are covered.
However, this question is easy to burst goose LL ah.
#include<bits/stdc++.h> #define LL long long #define N 100003 #define INF 10000000000000000 using namespace std; LL read() { LL x=0,f=1;char s=getchar(); while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();} while(s>='0'&&s<='9' ) {X = X * 10 + S- ' 0 ' ; S = getchar ();} return X * F; } LL Maxx = - . 1 , Minn = INF; int T [N], B [N]; int n-, m; LL a, B, C; LL STU [N], KE [N]; LL K1 = 0 , K2 = 0 , S = 0 ; // meet time subjects, the subjects do not satisfy the time, to meet the time the number of students LL SUM1 = 0 , sum2 = 0 , sum3 = 0 ; // meet subjects, subjects does not meet the time period, the number of students to meet the time * time LL ANS = INF; void WORK1 () { LL res=0; for(int i=1;i<=n;++i) if((LL)t[i]<maxx)res+=(LL)(maxx-t[i])*(LL)C; printf("%lld\n",res); } void work2() { for(int i=100000;i>=1;--i) { LL res=0; sum1-=ke[i]*i;k1-=ke[i]; sum2+=ke[i]*i;k2+=ke[i]; sum3- STU = [I] * I; S- = STU [I]; IF (I> Minn) Continue ; IF (SUM2!) Continue ; IF (A < B) { LL P = K1 * I-SUM1; // front satisfied LL Q = SUM2-K2 * I; // not satisfied later RES + = min (P, Q) * a; Q - = min (P, Q); IF (Q) RES + = Q * B; } the else { LL Q = K2 * I-SUM2; // not satisfied later RES + = Q * B; } ANS=min(ans,res); } printf("%lld\n",ans); } int main() { freopen("exam.in","r",stdin); freopen("exam.out","w",stdout); A=read(),B=read(),C=read(); n=read(),m=read(); for(int i=1;i<=n;++i)t[i]=read(),stu[t[i]]++,s++,sum3+=t[i],minn=min(minn,(LL)t[i]); for(int i=1;i<=m;++i)b[i]=read(),ke[b[i]]++,k1++,sum1+=b[i],maxx=max(maxx,(LL)b[i]); if(A==1000000000&&B==1000000000&&C<=100){work1();return 0;} if(C==10000000000000000){work2();return 0;} sort(t+1,t+1+n);sort(b+1,b+1+m); for(int i=100000;i>=1;--i) { LL res=0; sum1-=ke[i]*i;k1-=ke[i]; sum2+=ke[i]*i;k2+=ke[i]; sum3-=stu[i]*i;s-=stu[i]; if(!sum2)continue; if(A<B) { LL p=k1*i-sum1;//前面满足的 LL q=sum2-k2*i;//后面不满足的 res+=min(p,q)*A; q-=min(p,q); if(q)res+=q*B; } else { LL Q = K2 * I-SUM2; // not satisfied later RES + = Q * B; } RES + = (I-sum3 S *) * C; ANS = min (ANS, RES); } the printf ( " % LLD \ n- " , ANS); }