[Codeforces976E]Well played!(贪心)
Solution
首先可以证明,hp翻倍的操作一定是在同一个生物上最优
Code
#include <cstdio>
#include <algorithm>
#define ll long long
#define mx(i) max(A[i].hp,A[i].dmg)
#define N 200010
using namespace std; struct info{int hp,dmg,w;}A[N];
int n,a,b;
ll sum,Ans; inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
} int main(){
n=read(),a=read(),b=min(read(),n);
for(int i=1;i<=n;++i) A[i].hp=read(),A[i].dmg=read(),A[i].w=max(0,A[i].hp-A[i].dmg);
sort(A+1,A+n+1,[](info a,info b){return a.w>b.w;});
for(int i=1;i<=n;++i) sum+=((i<=b)?mx(i):A[i].dmg);
if(b==0){printf("%lld\n",sum);return 0;}
Ans=sum;
for(int i=1;i<=n;++i){
ll tmp=sum;
if(i<=b){
tmp-=mx(i);
tmp+=A[i].hp*(1ll<<a);
Ans=max(Ans,tmp);
}else{
tmp-=A[i].dmg;
tmp+=A[i].hp*(1ll<<a);
tmp-=mx(b);
tmp+=A[b].dmg;
Ans=max(Ans,tmp);
}
}
printf("%lld\n",Ans);
return 0;
}
[Codeforces976E]Well played!(贪心)的更多相关文章
- Codeforces976E Well played! 【贪心】
题目分析: 由于乘二的收获很大,所以我们可以证明乘的数一定是同一个,接着排序后依次选取,判断一下即可. 题目代码: #include<bits/stdc++.h> using namesp ...
- Educational Codeforces Round 43 E&976E. Well played! 贪心
传送门:http://codeforces.com/contest/976/problem/E 参考:https://www.cnblogs.com/void-f/p/8978658.html 题意: ...
- Educational Codeforces Round 43 E. Well played!(贪心)
E. Well played! time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #401 (Div. 2) A B C 水 贪心 dp
A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...
- hdoj--1087--Super Jumping! Jumping! Jumping!(贪心)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 786 Solved: 391[Submit][S ...
随机推荐
- (生产)js-base64 - 转码
参考:https://github.com/dankogai/js-base64 安装 $ npm install --save js-base64 使用 var Base64 = require(' ...
- The fourteenth day
A man is not old as long as he is seeking something. A man is not old until regrets take the place o ...
- <Android开源库 ~ 1> GitHub Android Libraries Top 100 简介
转载自GitHub Android Libraries Top 100 简介 本项目主要对目前 GitHub 上排名前 100 的 Android 开源库进行简单的介绍, 至于排名完全是根据 GitH ...
- CRM的划分
CRM提供完整的客户生命周期管理解决方案,帮助您管理各项与客户有关的事件,包括市场.销售以及客户支持等方面,优化事件处理流程,从而赢得更多客户,并提高客户满意度. 按企业经营类型划分 ...
- MySql 8.0.11 在win10下的zip非安装配置
在win10使用mysql8.0.11的zip包进行配置时,搜到的教程很多坑,特此总结成功配置的方法. 1.下载非安装的zip包 mysql 8.0.11 64位 2.解压zip包 将下载的zi ...
- Verilog八线 - 三线优先编码器设计(74LS148)
百度百科_74LS148 if语句法 //8线-3线优先编码器设计(74LS148) // //EI | A7 A6 A5 A4 A3 A2 A1 A0 | Y2 Y1 Y0 GS EO //0 | ...
- 数据结构(C#):图的最短路径问题、(Dijkstra算法)
今天曾洋老师教了有关于图的最短路径问题,现在对例子进行一个自己的理解和整理: 题目: 要求:变成计算出给出结点V1到结点V8的最短路径 答: 首先呢,我会先通过图先把从V1到V8的各种路径全部计算下来 ...
- Sliding Window - The Smallest Window II(AIZU) && Leetcode 76
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_B For a given array a1,a2,a3,...,aNa1 ...
- hdu-2838 Cow Sorting---逆序对的花费
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2838 题目大意: 就是求将之前的排列变成一个递增的排列,每交换两个数的代价为两个数的和,求变成递增的 ...
- 【HHHOJ】ZJOI2019模拟赛(十二)03.03 解题报告
点此进入比赛 得分: \(0+77+20=97\) 排名: \(Rank\ 5\) \(Rating\):\(+46\) \(T1\):[HHHOJ178]依神(点此看题面) 这套题目中的唯一一道传统 ...