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. 在UITableView中识别左右滑动,实现上下翻页的功能

    目前有三种方案: 1. UIScrollView + UITableView. 实现方法,在UIScrollView中,加入UITableView即可 设置UIScrollView的代理和方法 - ( ...

  2. ArcGIS Runtime SDK for Android 各版本下载地址

    ArcGIS Runtime SDK for Android各版本下载地址:ArcGIS Runtime SDK交流群:249819194 SDK包中主要包含以下内容: 其中里面比较重要的有以下几项: ...

  3. libmysqlclient.so.16未找到方法

    用mysql命令登录的时候报错: [root@iZ www]# mysql -uroot -p mysql: error while loading shared libraries: libmysq ...

  4. android sqlite3命令行检查自己的代码操作数据库是否正确

    真机调试的话需要root ,否则没有访问目录的权限 在 linux 的终端 或者 windows的cmd 中输入 adb shell 进入shell 环境 cd /data/data/程序包名/dat ...

  5. 解决dubbo的服务发布注解@service不能和事务注解不能共用的方案

    最近在项目的开发中遇到了一个问题,就是服务提供方使用@service发布dubbo服务时候,服务消费方@Reference无法注入bean导致空指针异常的问题.分析原因为@service注解并没有将服 ...

  6. C语言中的特殊变量

    auto: 函数中的局部变量,动态地分配存储空间,数据存储在动态存储区中,在调用该函数时系统会给它们分配存储空间,在函数调用结束时就自动释放这些存储空间. register: 为了提高效率,C语言允许 ...

  7. IOS 解析XML数据

    ●  什么是XML ●  全称是Extensible Markup Language,译作“可扩展标记语言” ●  跟JSON一样,也是常用的一种用于交互的数据格式 ●  一般也叫XML文档(XML ...

  8. 2018.8.19 mybatis 环境搭建---配置mysql 。(Windows环境下面)

    安装mysql Install/Remove of the Service Denied!错误的解决办法 在windos 的cmd下安装mysql 在mysql的bin目录下面执行: mysqld - ...

  9. Django:restframework与缓存By大熊

    http://chibisov.github.io/drf-extensions/docs/#cache-key 以上为drf-ext的文档 首先我们要下载两个东西,因为缓存我们用redis所以下 D ...

  10. web的监听器,你需要知道这些...

    一.简介 Listener是Servlet规范的另一个高级特性,它用于监听java web程序的事件,例如创建.修改.删除session,request,context等,并触发相应的处理事件,这个处 ...