题目链接

BZOJ3709

题解

贪心很显然

我们先干掉能回血的怪,当然按照\(d\)升序顺序,因为打得越多血越多,\(d\)大的尽量往后打

然后再干掉会扣血的怪,当然按照\(a\)降序顺序,因为最后受的伤害一定,回的血也一定,先尽量回多的血以尽量承受住当前伤害

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 100005,maxm = 100005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
struct node{int a,d,id;}a[maxn],b[maxn];
inline bool cmp1(const node& a,const node& b){
return a.d < b.d;
}
inline bool cmp2(const node& a,const node& b){
return a.a > b.a;
}
int n,ai,bi;
LL z;
int main(){
n = read(); z = read();
int x,y;
REP(i,n){
x = read(); y = read();
if (y >= x) a[++ai] = (node){y,x,i};
else b[++bi] = (node){y,x,i};
}
sort(a + 1,a + 1 + ai,cmp1);
for (int i = 1; i <= ai; i++){
if (z <= a[i].d){puts("NIE"); return 0;}
z = z - a[i].d + a[i].a;
}
sort(b + 1,b + 1 + bi,cmp2);
for (int i = 1; i <= bi; i++){
if (z <= b[i].d){puts("NIE"); return 0;}
z = z - b[i].d + b[i].a;
}
puts("TAK");
for (int i = 1; i <= ai; i++)
printf("%d ",a[i].id);
for (int i = 1; i <= bi; i++)
printf("%d ",b[i].id);
return 0;
}

最新文章

  1. spring xmlns 记录
  2. Java基本概念(1)什么是Java
  3. php中防止SQL注入的方法
  4. iOS 架构模式--解密 MVC,MVP,MVVM以及VIPER架构
  5. 第5.5次Scrum会议
  6. Python文件操作题
  7. Continuous Subarray Sum
  8. bzoj 1036 Tree Count
  9. Win7下Solr4.10.1和TomCat8的安装
  10. VS2010中xercesc配置及简单示例
  11. VC6神迹外挂的DIY
  12. 使用py2exe发布windows平台Python
  13. &quot;每日一道面试题&quot;.net托管堆是否会存在内存泄漏的情况
  14. mysql 外键和子查询,视图
  15. F - Tmutarakan Exams URAL - 1091 -莫比乌斯函数-容斥 or DP计数
  16. 20155326刘美岑2016-2017-2《Java程序设计》第一周学习总结
  17. [转]如何在本地apache上架设多个站点
  18. BZOJ 1340: [Baltic2007]Escape逃跑问题
  19. 【BZOJ】【1006】【HNOI2008】神奇的国度
  20. (剑指Offer)面试题3:二维数组中的查找

热门文章

  1. atomic是绝对的线程安全么?为什么?如果不是,那应该如何实现?
  2. Ubuntu Server 下将HTML页面转换为PNG图片
  3. Python序列及其操作(常见)
  4. spring boot 下使用@ConponentScan注解遇到的问题
  5. 【转载】OpenCV(C++ 与 Python 的比较)与 MATLAB 的比较
  6. Redis+Keepalived高可用方案详细分析
  7. cookie,localstorge,sessionstorge三者总结
  8. wpa_supplicant与kernel交互
  9. M2功能规格说明书
  10. Alpha冲刺——第三天