【Codeforces】976E Well played!
【题目大意】
给你n个行,每行一个 ,你有两种操作:
1.
2.
你可以进行A次1操作,B次2操作
问你最后 最大值。
【题解】
这个贪心很难想,就是将A个1操作全部放在一个 身上,使 ,那么就找 就可以了。
但是有一种数据可以卡住:5 1 18
7 3
7 6
8 6
8 5
1 2如果单纯这么写,那么算出来是39,可是实际上可以做到40,全部放在3上。
所以说枚举i,然后找出最大值罢了。
【代码如下】
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int n,A,B,t;LL Ans,Sum,Num;
struct xcw{LL hp,dam;bool operator <(const xcw b)const{return (hp-dam)>(b.hp-b.dam);}}a[200005];
LL read(){
LL ret=0;char ch=getchar();bool f=1;
for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');
for(; isdigit(ch);ch=getchar()) ret=ret*10+ch-'0';
return ret;
}
int main(){
// freopen("E.in","r",stdin);
// freopen("E.out","w",stdout);
n=read(),A=read(),B=read();
for(int i=1;i<=n;i++) a[i]=(xcw){read(),read()},Num+=a[i].dam;
if(!B){cout<<Num<<endl;return 0;}
sort(a+1,a+1+n);
for (int i=1;i<=B;i++) Sum+=max(0LL,a[i].hp-a[i].dam);
for (int i=1;i<=B;i++) Ans=max(Ans,Sum-max(0LL,a[i].hp-a[i].dam)-a[i].dam+(a[i].hp<<A));
for (int i=B+1;i<=n;i++) Ans=max(Ans,Sum-max(0LL,a[B].hp-a[B].dam)-a[i].dam+(a[i].hp<<A));
cout<<Ans+Num<<endl;
return 0;
}