Codeforces Educational Codeforces Round 43 E題
阿新 • • 發佈:2019-01-04
將hp加倍疊加在同一個人身上永遠是最優秀的解法。因此可以列舉疊加在誰身上,最後取一個最大值。需要注意的是b=0的情況,被hack了一波emmmm.
#include<bits/stdc++.h> using namespace std; #define rep(i,j,k) for(int i=j;i<=k;i++) typedef long long ll; struct node{ int de; int hp; }a[200005]; bool cmp(node a,node b){ return a.hp-a.de>b.hp-b.de; } int main(){ int n,t,b; cin>>n>>t>>b; rep(i,1,n) scanf("%d%d",&a[i].hp,&a[i].de); sort(a+1,a+1+n,cmp); ll tmp=0; if(b==n){ long long ans=0; rep(i,1,n) ans+=max(a[i].hp,a[i].de); tmp=max(ans,tmp); rep(i,1,n){ long long kt=1LL*ans-max(a[i].hp,a[i].de)+max(1LL*a[i].de,a[i].hp*1LL*(1LL<<t)); tmp=max(kt,tmp); } }else{ long long ans=0; rep(i,1,b) ans+=max(a[i].hp,a[i].de); rep(i,b+1,n) ans+=a[i].de; tmp=max(ans,tmp); rep(i,1,b){ long long kt=1LL*ans-max(a[i].hp,a[i].de)+max(1LL*a[i].de,a[i].hp*1LL*(1LL<<t)); tmp=max(kt,tmp); } if(b!=0) rep(i,b+1,n){ long long kt=1LL*ans-a[i].de+max(1LL*a[i].de,a[i].hp*1LL*(1LL<<t))-max(a[b].hp,a[b].de)+a[max(b,1)].de; tmp=max(kt,tmp); } } cout<<tmp<<endl; return 0; }