Educational Codeforces Round 43 E&976E. Well played! 贪心

传送门:http://codeforces.com/contest/976/problem/E

参考:https://www.cnblogs.com/void-f/p/8978658.html

题意:

对于每一个生物,有一个ph值和伤害值。现在有a次使ph值乘2的机会,有b次是伤害值等于ph值得机会。

问最后能得到最大的伤害总和是多少。

思路:

自己一开始也想的是贪心,但是贪的姿势不正确。明确,a次一定是给同一个生物放大的。但是至于是对哪一个生物放大,还是要用暴力一个一个去找,而不要对排序后第一个值操作;

 

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std;

#define lson (l, mid, rt << 1)
#define rson (mid + 1, r, rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back

#define Pll pair<ll, ll>
#define Pii pair<int, int>

#define fi first
#define se second

#define OKC                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;

/*-----------------show time----------------*/
const int maxn = 2e5 + 9;
int a, b, n;
struct node {
    ll h, d;
    ll w;
} t[maxn];
const ll inf = 0x3f3f3f3f3f3f3f3f;
int main() {
    OKC;
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++) {
        cin >> t[i].h >> t[i].d;
        t[i].w = t[i].h - t[i].d;
        if (t[i].w < 0) t[i].w = 0;
    }
    ll sum = 0;
    sort(t + 1, t + 1 + n, [](node a, node b) { return a.w > b.w; });
    for (int i = 1; i <= n; i++) {
        if (i <= b)
            sum += max(t[i].h, t[i].d);
        else
            sum += t[i].d;
    }
    ll ans = sum;
    if (b == 0)
        cout << ans << endl;
    else {
        for (int i = 1; i <= n; i++) {
            ll tmp = sum;
            if (i <= b) {
                tmp -= max(t[i].h, t[i].d);
                tmp += 1ll * (t[i].h << a);
            } else {
                tmp -= t[i].d;
                tmp += 1ll * (t[i].h << a);
                tmp += t[b].d;
                tmp -= max(t[b].d, t[b].h);
            }
            if (ans < tmp) ans = tmp;
        }
        cout << ans << endl;
    }

    return 0;
}
View Code

 

posted @ 2018-05-29 20:32  ckxkexing  阅读(199)  评论(0编辑  收藏  举报