E. Well played!
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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·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 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.

题意:有n行数字,每行有h[i],d[i].

你可以进行两种操作:

a:h[i]=2*h[i]

b:  d[i]=h[i].     两种操作只能分别进行 :a, b次。

问最后:sum(d[i])(i=1,2..n)的最大值。

思路:遍历一遍,对每个i进行a次操作,讨论最优情况取最大值。

代码:

 //#include"bits/stdc++.h"
#include<sstream>
#include<iomanip>
#include"cstdio"
#include"map"
#include"set"
#include"cmath"
#include"queue"
#include"vector"
#include"string"
#include"cstring"
#include"time.h"
#include"iostream"
#include"stdlib.h"
#include"algorithm"
#define db double
#define ll long long
#define vec vectr<ll>
#define mt vectr<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
//#define rep(i, x, y) for(int i=x;i<=y;i++)
#define rep(i, n) for(int i=0;i<n;i++)
const int N = 1e6+ ;
const int mod = 1e9 + ;
const int MOD = mod - ;
const int inf = 0x3f3f3f3f;
const db PI = acos(-1.0);
const db eps = 1e-;
using namespace std;
int n;
int A,B;
int a[N],b[N];
priority_queue<int,vector<int>,greater<int>> q;
int main() {
ll ans = ;
cin >> n >> A >> B;
for (int i = ; i < n; i++) {
cin >> a[i] >> b[i];
if (a[i] > b[i]) q.push(a[i] - b[i]);
}
for (int i = ; i < n; i++) ans += b[i];
while (q.size() > B) q.pop();
if (!B) return * pl(ans);
ll tans = ans;
for (int i = ; i < n; i++) {//讨论q长度与B的大小及i所处的位置
ll x = a[i] * (1LL << A);
if (q.size() && a[i] - b[i] >= q.top())
tans = max(tans, ans - (a[i] - b[i]) + x - b[i]);
else {
if (q.size() < B)
tans = max(tans, ans + x - b[i]);
else
tans = max(tans, ans - q.top() + x - b[i]);
}
}
while (q.size()) {
tans += q.top();
q.pop();
}
pl(tans);
}

Educational Codeforces Round 43 E. Well played!(贪心)的更多相关文章

  1. Educational Codeforces Round 43

    Educational Codeforces Round 43  A. Minimum Binary Number 显然可以把所有\(1\)合并成一个 注意没有\(1\)的情况 view code / ...

  2. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

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

    传送门:http://codeforces.com/contest/976/problem/E 参考:https://www.cnblogs.com/void-f/p/8978658.html 题意: ...

  4. Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心

    C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...

  5. Educational Codeforces Round 12 C. Simple Strings 贪心

    C. Simple Strings 题目连接: http://www.codeforces.com/contest/665/problem/C Description zscoder loves si ...

  6. Educational Codeforces Round 2 C. Make Palindrome 贪心

    C. Make Palindrome Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  7. Educational Codeforces Round 43 (Rated for Div. 2) ABCDE

    A. Minimum Binary Number time limit per test 1 second memory limit per test 256 megabytes input stan ...

  8. Educational Codeforces Round 2 C. Make Palindrome —— 贪心 + 回文串

    题目链接:http://codeforces.com/contest/600/problem/C C. Make Palindrome time limit per test 2 seconds me ...

  9. Educational Codeforces Round 25 D - Suitable Replacement(贪心)

    题目大意:给你字符串s,和t,字符串s中的'?'可以用字符串t中的字符代替,要求使得最后得到的字符串s(可以将s中的字符位置两两交换,任意位置任意次数)中含有的子串t最多. 解题思路: 因为知道s中的 ...

随机推荐

  1. IntelliJ IDEA详细配置和使用教程(转)

    http://blog.csdn.net/m_m254282520/article/details/78900238 关闭Intellij IDEA自动更新 在File->Settings-&g ...

  2. 【起航计划 019】2015 起航计划 Android APIDemo的魔鬼步伐 18 App->Device Admin 设备管理器 DeviceAdminReceiver DevicePolicyManager PreferenceActivity的使用

    Device Admin示例介绍了类DeviceAdminReceiver,DevicePolicyManager和ActivityManager. 使用DevicePolicyManager这个类, ...

  3. 【Unity3D学习笔记】解决放大后场景消失不显示问题

    不知道为啥,我的Unity场景放大到一定大小后,就会消失... 解决方案: 选中一个GameObject,然后按F键. F键作用是聚焦,视图将移动,以选中对象为中心.

  4. ZIP文件压缩和解压

    最近要做一个文件交互,上传和下载, 都是zip压缩文件,所以研究了下,写了如下的示例 注意引用  ICSharpCode.SharpZipLib.dll 文件 该dll文件可以到官方网站去下载, 我这 ...

  5. Tomcat 中部署 web 应用 ---- Dubbo 服务消费者 Web 应用 war 包的部署

    使用Maven构建Dubbo服务的可执行jar包 Dubbo服务的运行方式: 1.使用Servlet容器运行(Tomcat.Jetty等)----不可取 缺点:增加复杂性(端口.管理) 浪费资源(内存 ...

  6. sql注入【手工及一些工具】

    Sql注入原理分析: 网站程序存在可控传递参数,参数未进行过滤直接带入数据库查询,导致攻击者可通过传递恶意sql语句代码进行执行攻击. Sql注入产生条件 1.必须有参数传递 2.参数值带入数据库查询 ...

  7. JavaScript如何转换数据库DateTime字段类型?

    Javascript一种直译式脚本语言,是一种动态类型.弱类型.基于原型的语言,内置支持类型.它的解释器被称为JavaScript引擎,为浏览器的一部分,广泛用于客户端的脚本语言,最早是在html(标 ...

  8. 【转载】#335 - Accessing a Derived Class Using a Base Class Variable

    You can use a variable whose type is a base class to reference instances of a derived class. However ...

  9. python 爬poj.org的题目

    主要是正则表达式不熟练,基础知识不扎实,函数也不怎么会用,下次再深入了解这3个函数吧. 主要是一个翻页的功能,其实,就是通过一个url替换一下数字,然后得到一个新的url,再找这个新的链接的信息. # ...

  10. Poj(2236),简单并查集

    题目链接:http://poj.org/problem?id=2236 思路很简单,傻逼的我输出写成了FALL,然后遍历的时候for循环写错了,还好很快我就Debug出来了. #include < ...