Educational Codeforces Round 43 E. Well played!(贪心)
1 second
256 megabytes
standard input
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:
- Doubles health of the creature (hpi := hpi·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.
The first line contains three integers 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 hpi and dmgi (1 ≤ hpi, dmgi ≤ 109) — description of the i-th creature.
Print single integer — maximum total damage creatures can deal.
2 1 1
10 15
6 1
27
3 0 3
10 8
7 11
5 2
26
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!(贪心)的更多相关文章
- Educational Codeforces Round 43
Educational Codeforces Round 43 A. Minimum Binary Number 显然可以把所有\(1\)合并成一个 注意没有\(1\)的情况 view code / ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 43 E&976E. Well played! 贪心
传送门:http://codeforces.com/contest/976/problem/E 参考:https://www.cnblogs.com/void-f/p/8978658.html 题意: ...
- Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心
C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...
- Educational Codeforces Round 12 C. Simple Strings 贪心
C. Simple Strings 题目连接: http://www.codeforces.com/contest/665/problem/C Description zscoder loves si ...
- Educational Codeforces Round 2 C. Make Palindrome 贪心
C. Make Palindrome Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- 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 ...
- Educational Codeforces Round 2 C. Make Palindrome —— 贪心 + 回文串
题目链接:http://codeforces.com/contest/600/problem/C C. Make Palindrome time limit per test 2 seconds me ...
- Educational Codeforces Round 25 D - Suitable Replacement(贪心)
题目大意:给你字符串s,和t,字符串s中的'?'可以用字符串t中的字符代替,要求使得最后得到的字符串s(可以将s中的字符位置两两交换,任意位置任意次数)中含有的子串t最多. 解题思路: 因为知道s中的 ...
随机推荐
- java-logic====吃货联盟
1.系统界面 2.功能一 3.查看餐袋 4.签收订单 5.删除订单 6.我要点赞 主要分在两个类中: 第一个类entity,主要的是一些共有的属性 主要代码: public class entity ...
- 位运算(2)——Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...
- BZOJ3261: 最大异或和(可持久化trie树)
题意 题目链接 Sol 设\(sum[i]\)表示\(1 - i\)的异或和 首先把每个询问的\(x \oplus sum[n]\)就变成了询问前缀最大值 可持久化Trie树维护前缀xor,建树的时候 ...
- SAP常用函数
1.获取月末最后一天日期 DATA LAST_DATE TYPE SY-DATUM. CALL FUNCTION 'LAST_DAY_OF_MONTHS' EXPORTING day_in = sy- ...
- Java笔记 —— 继承
Java笔记 -- 继承 h2{ color: #4ABCDE; } a{ text-decoration: none!important; } a:hover{ color: red !import ...
- sql数据库常用操作
string connectionString = @"Data Source=(local)\sql2008r2;Initial Catalog=Movies;Uid=sa;Pwd=sql ...
- 使用坚果云+keepass实现网盘密码管理
准备工作 登录坚果云web版 在主页创建了一个新的同步文件夹AAA(与同步文件夹My Nutstore并列) 设置同步文件夹AAA:勾选“默认不同步到电脑” 把KeePass的数据库文件db.kdbx ...
- HTC vive VR设备软硬件安装+运行unity开发的VR程序
总结在HTC vive VR开发过程中的HTC vive的安装调试 1.首先确保电脑的配置满足要求: 进入官网,测试电脑是否满足要求 链接:https://www.vive.com/us/produc ...
- andriod给ListView中的TextView增加跑马灯效果
正常情况下跑马灯效果只需要在TextView中添加android:ellipsize="marquee" android:singleLine="true" a ...
- 2018.7.23 oracle中的CLOB数据类型
Oarcle中的LOB类型 1.在Oracle中,LOB(Large Object,大型对象)类型的字段现在用得越来越多了.因为这种类型的字段,容量大(最多能容纳4GB的数据),且一个表中可以有多个这 ...