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. psd图片不能在网页上显示

    原因:web上不支持psd图片,web支持JPG,PNG等. 解决:打开ps点击文件--储存为web所用格式(选择转换成哪种格式).

  2. better-scroll 遇到的问题 1

    备注:better-scroll 实现下拉,是父子层的结构,父层的第一个子元素,如果超出父容器,那么就可以实现下拉 问题:  今天在使用better-scroll实现下拉功能,遇到了一个问题 &quo ...

  3. u-boot分析(十一)----MMU简单分析|u-boot分析大结局|学习规划

    u-boot分析(十一) 通过前面十篇博文,我们已经完成了对BL1阶段的分析,通过这些分析相信我们对u-boot已经有了一个比较深入的认识,在BL2阶段大部分是对外设的初始化,并且有的我们已经分析过, ...

  4. win10 安装mysql zip 压缩包版

    从官网下载zip https://www.mysql.com/downloads/ 解压 D:\devtool\mysql-5.7.17-winx64\ 将  D:\devtool\mysql--wi ...

  5. [Maven]Eclipse集成遇到的问题

    当maven项目导入到eclipse中后使用eclipse提供的maven命令执行任意一个出现 Exception in thread "main" java.lang.Unsup ...

  6. Linux 下安装使用 oh-my-zsh

    Ubuntu 下安装 oh-my-zsh 安装 zsh sudo apt install zsh 安装 git(如果你的系统没有自带的话) sudo apt install git 安装 oh-my- ...

  7. 微信小程序之性能优化

    如果做前端仅仅停留在编码和实现业务功能上面,可能进步速度会有些慢,但是如果经历了对页面的性能优化之后而且有所成绩的话那就不同了,因为你对他背后的机制进行了研究,才能做好性能优化. 做微信小程序也是一样 ...

  8. Linux 使用第三方邮箱发邮件的设置

    mail命令在Ubuntu下是需要安装的,使用下条命令进行安装: sudo apt-get install heirloom-mailx 在CentOS 下安装则是: yum install mail ...

  9. Tensorflow ValueError: Protocol message RewriterConfig has no "layout_optimizer" field

    I changed models/research/object_detection/exporter.py line 71/72 from: rewrite_options = rewriter_c ...

  10. ODBC驱动程序丢失解决方法

    今天运行SqlDbx连接数据库的时候报错,提示没有找到相应的ODBC driver,打开ODBC管理面板一看,发现里面的驱动程序都不见了.这时想起今天卸载了一个成本核算软件后成这样的,网上搜索一下只需 ...