我们要出租的话,一定是出租产奶量最少的牛

那我们就看出租多少头牛(其他的卖奶)的时候答案最大就可以了。

(注意N有可能小于R)

 #include<bits/stdc++.h>
#define ll long long
#define pa pair<int,int>
using namespace std;
const int maxn=; inline ll rd(){
ll x=;char c=getchar();
while(c<''||c>'') c=getchar();
while(c>=''&&c<='') x=x*+c-'',c=getchar();
return x;
} int N,M,R,C[maxn],S[maxn];
pa PQ[maxn];
ll ans,tmp,tmp2; inline bool cmp(int a,int b){return a>b;}
inline bool cmp2(pa a,pa b){return a>b;} int main(){
int i,j,k;
N=rd(),M=rd(),R=rd();
for(i=;i<=N;i++) C[i]=rd();
for(i=;i<=M;i++) PQ[i].second=rd(),PQ[i].first=rd();
for(i=;i<=R;i++) S[i]=rd();
sort(C+,C+N+,cmp);sort(PQ+,PQ+M+,cmp2);sort(S+,S+R+,cmp);
R=min(N,R);for(i=;i<=R;i++) tmp2+=S[i];
for(i=,j=;i<=N;i++){
for(;j<=M&&PQ[j].second<C[i];j++)
tmp+=1LL*PQ[j].first*PQ[j].second,C[i]-=PQ[j].second;
tmp+=1LL*PQ[j].first*C[i],PQ[j].second-=C[i];
ans=max(ans,tmp+tmp2);tmp2-=S[N-i];
}printf("%lld\n",ans);
}
05-11 22:43