Codeforces976E Well played!

题意:n个怪物,没每个怪物有血量和攻击力,有两种操作,第一种使得生命翻倍,第二种使得伤害等于生命值,第一种最多a次,第二种最多b次,问最后所有怪的总攻击力多少

题解:贪心,第一种操作一定加在一直怪上最优,如果不考虑攻击力,也就是要使得生命值最高,所以加在同一只怪上更优

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
struct node{ll h, d, m;}t[200100];
ll n, a, b, s1, s2, ans;
int main(){
    ios::sync_with_stdio(0);
    cin>>n>>a>>b;
    b = min(b, n);
    for(ll i=0;i<n;i++){
        cin>>t[i].h>>t[i].d;
        t[i].m = max(0LL, t[i].h-t[i].d);
        s1 += t[i].d;
    }
    if(!b) {cout<<s1<<endl;return 0;}
    sort(t, t+n, [](node aa,node bb){return aa.m>bb.m;});
    for(ll i=0;i<b;i++) s2 += t[i].m;
    for(ll i=0;i<n;i++) ans = max(ans, s2-t[i<b?i:(b-1)].m+(t[i].h<<a)-t[i].d);
    cout<<s1+ans<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/Noevon/p/8977211.html