[Codeforces976E]Well played!(贪心)

[不稳定的传送门]

Solution

首先可以证明,hp翻倍的操作一定是在同一个生物上最优

Code

#include <cstdio>
#include <algorithm>
#define ll long long
#define mx(i) max(A[i].hp,A[i].dmg)
#define N 200010
using namespace std;

struct info{int hp,dmg,w;}A[N];
int n,a,b;
ll sum,Ans;

inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int main(){
	n=read(),a=read(),b=min(read(),n);
	for(int i=1;i<=n;++i) A[i].hp=read(),A[i].dmg=read(),A[i].w=max(0,A[i].hp-A[i].dmg);
	sort(A+1,A+n+1,[](info a,info b){return a.w>b.w;});
	for(int i=1;i<=n;++i) sum+=((i<=b)?mx(i):A[i].dmg);
	if(b==0){printf("%lld\n",sum);return 0;}
	Ans=sum;
	for(int i=1;i<=n;++i){
		ll tmp=sum;
		if(i<=b){
			tmp-=mx(i);
			tmp+=A[i].hp*(1ll<<a);
			Ans=max(Ans,tmp);
		}else{
			tmp-=A[i].dmg;
			tmp+=A[i].hp*(1ll<<a);
			tmp-=mx(b);
			tmp+=A[b].dmg;
			Ans=max(Ans,tmp);
		}
	}
	printf("%lld\n",Ans);
	return 0;
}

猜你喜欢

转载自www.cnblogs.com/void-f/p/8978658.html