题目链接:
http://codeforces.com/contest/976/problem/E
题目:
Recently Max has got himself into popular CCG “BrainStone”. As “BrainStone” is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:
Max owns n creatures, i-th of them can be described with two numbers — its health hpi and its damage dmgi. Max also has two types of spells in stock:
Doubles health of the creature (hpi=hpi×2)(hpi=hpi×2);
Assigns value of health of the creature to its damage (dmgi=hpi)(dmgi=hpi).
Spell of first type can be used no more than a times in total, of the second type — no more than b times in total. Spell can be used on a certain creature multiple times. Spells can be used in arbitrary order. It isn’t necessary to use all the spells.
Max is really busy preparing for his final exams, so he asks you to determine what is the maximal total damage of all creatures he can achieve if he uses spells in most optimal way.
Input
The first line contains three integers n,a,b(1 ≤ n ≤ 2⋅105,0 ≤ a ≤ 20,0 ≤ b ≤ 2⋅105)n,a,b(1 ≤ n ≤ 2·105,0 ≤ a ≤ 20,0 ≤ b ≤ 2·105) — the number of creatures, spells of the first type and spells of the second type, respectively.
The i-th of the next n lines contain two number hpihpi and dmgi(1 ≤ hpi, dmgi ≤ 109)dmgi(1 ≤ hpi, dmgi ≤ 109) — description of the i-th creature.
Output
Print single integer — maximum total damage creatures can deal.
Examples
input
2 1 1
10 15
6 1
- 1
- 2
- 3
output
27
- 1
input
3 0 3
10 8
7 11
5 2
- 1
- 2
- 3
- 4
output
26
- 1
Note
In the first example Max should use the spell of the first type on the second creature, then the spell of the second type on the same creature. Then total damage will be equal to 15 + 6⋅2 = 2715 + 6·2 = 27.
In the second example Max should use the spell of the second type on the first creature, then the spell of the second type on the third creature. Total damage will be equal to 10 + 11 + 5 = 2610 + 11 + 5 = 26.
题意:
有n
个物品,能进行一类操作a
次和二类操作b
次,每个物品有一个权x
和权y
,一类操作为把某个物品的x
变为原来的两倍,二类操作为令某个物品的y = x
,问这n
个物品的y
的总和最大是多少。
思路:
不难证明,如果要对某个物品进行加倍的话,那么剩余的加倍次数也都要分给这个物品,所以我们可以枚举对哪个物品进行加倍,统计答案即可。
//贪心
#include <bits/stdc++.h> const int maxn = int(2e5) + 7; struct Node { long long x, y; bool operator < (const Node &tmp) const { return x - y > tmp.x - tmp.y; } } node[maxn]; int main() { // freopen("in.txt", "r", stdin); long long sum = 0; int a, b, n; scanf("%d%d%d", &n, &a, &b); for (int i = 1; i <= n; i++) scanf("%lld%lld", &node[i].x, &node[i].y); std::sort(node + 1, node + 1 + n); for (int i = 1; i <= b; i++) sum += std::max(node[i].x, node[i].y); for (int i = b + 1; i <= n; i++) sum += node[i].y; long long ans = sum; for (int i = 1; i <= b; i++) ans = std::max(ans, sum - std::max(node[i].x, node[i].y) + (node[i].x << a)); sum = sum - std::max(node[b].x, node[b].y) + node[b].y; for (int i = b + 1; i <= n && b; i++) ans = std::max(ans, sum - node[i].y + (node[i].x << a)); printf("%lld ", ans); return 0; }