[BZOJ3709][PA2014]Bohater[贪心]
按照加减血量排序,杀完能加血的放在前面,但有个地方要注意,就是如果两个怪物杀死都能加血的话,要把减少血量少的放在前面
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+7;
struct Data{
int x, y, ord;
inline bool operator < (const Data & rhs) const {
int a = y - x, b = rhs.y - rhs.x;
if (a >= 0 && b >= 0) return x < rhs.x;
if (a * b <= 0) return a >= 0;
return y > rhs.y;
}
}b[MAXN];
int n;
long long m;
int main(void) {
scanf("%d%lld", &n, &m);
for(int i = 1; i <= n; ++i) {
scanf("%d%d", &b[i].x, &b[i].y);
b[i].ord = i;
}
sort(b+1, b+1+n);
for(int i = 1; i <= n; ++i) {
m -= b[i].x;
if (m <= 0) return puts("NIE"), 0;
m += b[i].y;
}
puts("TAK");
for(int i = 1; i <= n; ++i) printf("%d ", b[i].ord);
return 0;
}