BZOJ3709 [PA2014]Bohater 【贪心】

题目链接

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;
}

posted @ 2018-05-26 11:23  Mychael  阅读(160)  评论(0编辑  收藏  举报