Codeforces 976E

题意略。

思路:

容易知道那a次倍增放在同一个怪身上是最优的,其余的怪我们只需要取hp值和damage值中间最大的那个就好了(在b值的限制下)。

然而我们并不知道把那a次倍增放在哪个怪身上最好,那么我们就只能一只一只地试。

#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
typedef long long LL;

struct node{
    LL hp,dmg;
    node(LL a = 0,LL b = 0){
        hp = a,dmg = b;
    }
};

LL pwr2[30];
node store[maxn];
int n,a,b;

bool cmp(const node& nd1,const node& nd2){
    return (nd1.hp - nd1.dmg) > (nd2.hp - nd2.dmg);
}

int main(){
    scanf("%d%d%d",&n,&a,&b);
    for(int i = 0;i < n;++i) scanf("%lld%lld",&store[i].hp,&store[i].dmg);
    sort(store,store + n,cmp);
    LL sum = 0;
    for(int i = 0;i < n;++i){
        if(i < b) sum += max(store[i].dmg,store[i].hp);
        else sum += store[i].dmg;
    }
    LL ans = sum;
    for(int i = 0;i < b;++i){
        LL tmp = sum;
        tmp -= max(store[i].dmg,store[i].hp);
        tmp += max(store[i].hp<<a,store[i].dmg);
        ans = max(ans,tmp);
    }
    if(b > 0){
        sum -= max(store[b - 1].dmg,store[b - 1].hp);
        sum += store[b - 1].dmg;
        for(int i = b;i < n;++i){
            LL tmp = sum;
            tmp -= store[i].dmg;
            tmp += max(store[i].hp<<a,store[i].dmg);
            ans = max(ans,tmp);
        }
    }
    printf("%lld\n",ans);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/tiberius/p/9032035.html