原题:
E. Well played!
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.

Input
The first line contains three integers n, a, b (1 ≤ n ≤ 2·10^5, 0 ≤ a ≤ 20, 0 ≤ b ≤ 2·10^5) — 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 ≤ 10^9) — description of the i-th creature.

Output
Print single integer — maximum total damage creatures can deal.

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

中文:

给你一堆士兵,每个士兵有生命值和战斗力,你作为指挥官有两个能力,第一个是任意指定一个士兵把他的生命值×2,另一个是把他的生命值变成他的攻击力。现在给你a次使用第一种能力,b次使用第二种能力的机会,问你这些士兵总的战斗力最大是多少?

代码:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 200001;
typedef long long ll;int a,b,n;struct node
{ll hp,dam;bool ex;
};node ns[maxn];
ll pow2[21];
vector<node> vn;
int cmp(const node &n1,const node &n2)
{if(n1.hp-n1.dam!=n2.hp-n2.dam)return n1.hp-n1.dam>n2.hp-n2.dam;return n1.hp>n2.hp;
}int main()
{ios::sync_with_stdio(false);pow2[0]=1;for(int i=1;i<=20;i++)pow2[i]=pow2[i-1]*2;while(cin>>n>>a>>b){vn.clear();int ind=0;ll tmp=0,ans=0;ll res=pow2[a];for(int i=1;i<=n;i++){cin>>ns[i].hp>>ns[i].dam;ns[i].ex=0;ans+=ns[i].dam;}sort(ns+1,ns+1+n,cmp);for(int i=1,j=1;i<=n&&j<=b;i++,j++){if(ns[i].hp>ns[i].dam){ind++;ns[i].ex=1;ans-=ns[i].dam;ans+=ns[i].hp;}}if(b==0){cout<<ans<<endl;continue;}if(ind<b){tmp=ans;for(int i=1;i<=n;i++){if(ns[i].ex){if(ans-ns[i].hp+ns[i].hp*res>tmp)//被换过{tmp=ans-ns[i].hp+ns[i].hp*res;}}else//没被换过{if(ans-ns[i].dam+ns[i].hp*res>tmp){tmp=ans-ns[i].dam+ns[i].hp*res;}}}cout<<tmp<<endl;}else//ind == b{tmp=ans;for(int i=1;i<=n;i++){if(ns[i].ex){if(ans-ns[i].hp+ns[i].hp*res>tmp)//被换过{tmp=ans-ns[i].hp+ns[i].hp*res;}}else//没被换过{if(ans-ns[ind].hp+ns[ind].dam-ns[i].dam+ns[i].hp*res>tmp)//最小的{tmp=ans-ns[ind].hp+ns[ind].dam-ns[i].dam+ns[i].hp*res;}}}cout<<tmp<<endl;}}return 0;
}

思路:

首先把所有原有士兵的战斗值都都加起来,记为ans。

对所有士兵进行排序,排序按照士兵的生命值减去战斗的大小,从大到小排序。

将排序后的士兵,从头开始,把生命值赋给战斗力,这里注意,替换的次数要小于b,同时记录替换了多少个,记为ind,而且要替换生命值大于战斗力的,如果不满足要求则break。

如果题目中给定的b为0,那么直接输出ans。

接下来要找这么一个士兵,将他的生命值翻成2^a的倍数,然后赋给他的生命值。此处可以得知如果要在这n个士兵的生命进行翻倍,然后赋给战斗力,那么一定是找其中一个最生命最大的,让他翻2^a倍,而不是用某种策略将翻倍的次数均摊给某些士兵。

遍历所有士兵,判断该士兵是否之前将生命值换给战斗力,如果没有换过,那么判断ind值。

如果ind值小于b次,那么表示还能继续使用赋值的操作,判断将该士兵生命值翻倍并赋给战斗力后,与原来的ans比较,如果比ans大,则更新。

如果ind值等于b次,那么就要挑一个生命值减去战斗力值最小的,而且被替换过生命和战斗力的士兵,把他的生命和战斗力替换回来,同样使用上一段的操作更新ans。

如果该士兵的生命值和战斗力更换过,那么就直接将他的生命提高2^a倍,然后重新赋值给战斗力,更新ans值即可。

cf Educational Codeforces Round 43 E. Well played!相关推荐

  1. cf Educational Codeforces Round 133 C. Robot in a Hallway

    原题: There is a grid, consisting of 2 rows and m columns. The rows are numbered from 1 to 2 from top ...

  2. cf Educational Codeforces Round 85 (Rated for Div. 2)B. Middle Class

    题目链接:https://codeforces.com/contest/1334/problem/B B. Middle Class time limit per test2 seconds memo ...

  3. CF Educational Codeforces Round 57划水记

    因为是unrated于是就叫划水记了,而且本场也就用了1h左右. A.B:划水去了,没做 C:大水题,根据初三课本中圆的知识,可以把角度化成弧长,而这是正多边形,所以又可以化成边数,于是假设读入为a, ...

  4. cf Educational Codeforces Round 49 D. Mouse Hunt

    原题: Medicine faculty of Berland State University has just finished their admission campaign. As usua ...

  5. cf Educational Codeforces Round 54 C. Meme Problem

    原题: C. Meme Problem time limit per test1 second memory limit per test256 megabytes inputstandard inp ...

  6. cf Educational Codeforces Round 134 E. Prefix Function Queries

    原题: You are given a string s, consisting of lowercase Latin letters. You are asked q queries about i ...

  7. cf Educational Codeforces Round 77 E. Tournament

    原题: E. Tournament time limit per test2 seconds memory limit per test256 megabytes inputstandard inpu ...

  8. cf Educational Codeforces Round 44 C. Liebig's Barrels

    原题: C. Liebig's Barrels time limit per test2 seconds memory limit per test256 megabytes inputstandar ...

  9. cf Educational Codeforces Round 48 C. Vasya And The Mushrooms

    原题: C. Vasya And The Mushrooms time limit per test2 seconds memory limit per test256 megabytes input ...

最新文章

  1. 【2019-06-11】笔耕不辍
  2. 前端中会用到的设计模式之单一职责原则
  3. 最简单的iOS网络请求
  4. oracle进程对文件没有写权限,ORACLE SYS用户没有权限一天半的救库过程
  5. 计算机视野仪检测青光眼的操作,计算机视野仪检测青光眼的操作及体会
  6. [USACO1.5]数字三角形 Number Triangles
  7. apache 二级域名设置
  8. Android 调用12306接口,GitHub - AndroidyxChen/loading-12306: 仿PC端12306的刷新loading的自定义view...
  9. 移动混合开发之android文件管理新建文件和删除文件
  10. DecimalFormat
  11. SQL SERVER 用户自定义函数如何定义.
  12. asp.net学习之ado.net(无连接模式中的DataAdapter)
  13. python变量未定义_引入模块的全局变量未定义
  14. 2020年python考试时间_想准备2021年三月份的Python考试,应该怎么准备呢?
  15. python自动化webdriver_轻松自动化---selenium-webdriver(python) (六)
  16. 游戏排行榜实现mysql_游戏中百万用户排行设计与实现
  17. 完美国际服务器维护中,《完美国际2》3月31日全服更新维护公告
  18. snprintf函数的用法详解
  19. 二叉树——二叉树的深度
  20. Spring框架核心思想

热门文章

  1. 防火墙无法打开,错误代码 0×80070422
  2. 服务器 日志打印 中文变乱码
  3. 学了mysql能做什么的_学sql能干什么
  4. 四年级上册数学计算机的教学视频,人教版小学四年级数学上册教学视频
  5. 李开复“埋雷”,蚂蚁拆弹
  6. 安装descriptastorus
  7. 计算机的存储程序是谁提出来的,计算机储存程序和程序原理是谁提出来的
  8. 快速p掉多余内容ps修改ps去人物ps改图ps视频教程学习
  9. 阿里云轻量型服务器有什么用处?
  10. @echo off和echo off的区别