P4181 [USACO18JAN] Rental Service S
1.卖牛奶先卖给出价高的商铺;
2.把奶牛租给出价高的邻居。
3.牛奶,租牛价格 等价-> 贪心
>>>若` cow的前缀和 ->重复的过程循环_->动态记录 ans
>>>商铺只 购买 QI 加仑
/* 175 295 355 385 400 725 495 495 495 495 495 495 965 */ #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<bits/stdc++.h> #define ll long long #define ddd printf("-----------------debug\n"); using namespace std; const int maxn=1e6+10; int n,m,r; ll cow[maxn],zu[maxn]; //ll ans=0,ANS=0,tmp_jl;//////////////////////////// struct store{ ll prc,jl; }str[maxn]; bool cmp1(ll a,ll b){ return a>b; } bool cmp2(store a,store b){ return a.prc>b.prc; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>m>>r; for(int i=1;i<=n;i++) cin>>cow[i]; sort(cow+1,cow+1+n,cmp1); for(int i=1;i<=m;i++) cin>>str[i].jl>>str[i].prc; sort(str+1,str+1+m ,cmp2); for(int i=1;i<=r;i++) cin>>zu[i]; sort(zu+1,zu+1+r,cmp1); for(int i=2;i<=r;i++) zu[i]+=zu[i-1]; int t=1; ll ans=0,ANS=0,tmp_jl;///////////////////////////////// for(int i=0;i<=n;i++) { tmp_jl+=cow[i]; while(t<=m&&tmp_jl>=str[t].jl){ ans+=str[t].jl*str[t].prc; tmp_jl-=str[t].jl; t++; } if(tmp_jl>0&&t<=m ){ ans+=tmp_jl*str[t].prc; str[t].jl-=tmp_jl; tmp_jl=0; } ANS=max( ANS,ans+zu[min(r,n-i)] ); } cout<<ANS<<'\n'; return 0; }

浙公网安备 33010602011771号