Educational Codeforces Round 43 Well played!

Well played!

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:

  1. Doubles health of the creature (hpi := hpi·2);
  2. Assigns value of health of the creature to its damage (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 nab (1 ≤ n ≤ 2·1050 ≤ a ≤ 200 ≤ 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 hpi and dmgi (1 ≤ hpi, dmgi ≤ 109) — description of the i-th creature.

Output

Print single integer — maximum total damage creatures can deal.

Examples
input
Copy
2 1 1
10 15
6 1
output
Copy
27
input
Copy
3 0 3
10 8
7 11
5 2
output
Copy
26
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 = 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 = 26.


The meaning of the question: Each monster has health and damage, 1 operation for a total of a times, each time you can double the health, 2 operations for a total of b times, each time you can convert health into damage,

Ask you what the total damage you can get in the end.

Idea: Fire attacking the heart, it must be the best for us to use a times on a monster. If it is not the best, we use m times for 1 monster and n times for 2 monsters, then we can definitely use only a certain monster. The use of Warcraft achieves better results (because it is a doubling operation), so we can enumerate the use of that Warcraft.

预处理魔兽,让h-d最大且大于0的先转化,然后做d的和,然后枚举每个魔兽的的时候如果操作a次后发现

①不值得转化,h<d,枚举下一个

②值得转化且此前分配给他b操作了,直接转化算总和

③值得转化且此前没分配给他b操作,还剩余有b操作,直接转化算总和

④值得转化且此前没分配给他b操作,没有b操作了,把转化率最低的那个分配给他(这个也可以预处理得到),求总和

代码:

#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
using namespace std;
typedef long long ll;
const int maxn = 1e6+5;
const double esp = 1e-12;
const int ff = 0x3f3f3f3f;
map<int,int>::iterator it;
struct node
{
	ll h,d;
	int mk;
} p[maxn];

ll n,a,b;

bool cmp(node x,node y)
{
	return x.h-x.d< y.h-y.d;
}

ll quick_pow(ll x,ll y)
{
	ll ans = 1;
	while(y)
	{
		if(y&1)
			ans*= x;
		x*= x;
		y>>= 1;	
	}
	
	return ans;
}

int main()
{
	mem(p,0);
	cin>>n>>a>>b;
	
	for(int i = 1;i<= n;i++)
		scanf("%lld %lld",&p[i].h,&p[i].d);
	
	sort(p+1,p+n+1,cmp);
	
	int last = n+1;//记录转化率最低的魔兽 
	for(int i = n;i>= 1;i--)
	{
		if(p[i].h-p[i].d> 0&&b> 0)
			p[i].mk = 1,b--;
		else
			break;
		last--;
	}
	
	ll sum = 0;
	for(int i = 1;i<= n;i++)
		if(p[i].mk)
			sum+= p[i].h;
		else
			sum+= p[i].d;
	
	ll ans = sum;
	for(int i = 1;i<= n;i++)
	{
		ll tmp = p[i].h*quick_pow(2,a);
		
		ll d = 0;
		if(p[i].mk)
			d = sum-p[i].h+tmp;
		else if(tmp> p[i].d)
		{
			if(b> 0)
				d = sum-p[i].d+tmp;
			else if(last<= n)
				d = sum-p[last].h+p[last].d-p[i].d+tmp;
		}
		years = max(years,d);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325902889&siteId=291194637