Codeforces976E Well played! 【贪心】

时间:2023-03-10 00:38:24
Codeforces976E Well played! 【贪心】

题目分析:

  由于乘二的收获很大,所以我们可以证明乘的数一定是同一个,接着排序后依次选取,判断一下即可。

题目代码:

 #include<bits/stdc++.h>
using namespace std; const int maxn = ; int n,a,b; struct node{
int hp,dm;
}d[maxn]; int cmp(node alpha,node beta){
return alpha.hp-alpha.dm > beta.hp-beta.dm;
} void read(){
scanf("%d%d%d",&n,&a,&b);
for(int i=;i<=n;i++) scanf("%d%d",&d[i].hp,&d[i].dm);
sort(d+,d+n+,cmp);
} void work(){
int hh = ;
long long ext = ,ans = ;
for(int i=;i<=a;i++) hh *= ;
int pt;
for(pt=;pt<=min(b,n);pt++){
if(d[pt].hp-d[pt].dm <= ) break;
ans += d[pt].hp;
}
for(int i=pt;i<=n;i++) ans += d[i].dm;
long long em = ans;ext = ans;pt--;
if(b == ){printf("%lld",ext);return;}
for(int i=;i<=n;i++){
em = ans;
if(i<=pt){
em = em-d[i].hp+(1ll*d[i].hp*hh);
ext = max(ext,em);
}else{
if(pt < b){
em = em+(1ll*d[i].hp*hh)-d[i].dm;
ext = max(ext,em);
}else{
em = em-d[pt].hp+(1ll*d[i].hp*hh)-d[i].dm+d[pt].dm;
ext = max(ext,em);
}
}
}
printf("%lld",ext);
} int main(){
read();
work();
return ;
}