#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
struct Mon {
ll i, d, a;
ll gain() const {return a-d;}
};
bool cpos(const Mon& x, const Mon& y) {return x.d < y.d;}
bool cneg(const Mon& x, const Mon& y) {return x.a > y.a;}
vi solve() {
ll n, hp;
scanf("%lld%lld", &n, &hp);
vector<Mon> pos, neg;
for(int i=1; i<=n; ++i) {
ll d, a;
scanf("%lld%lld", &d, &a);
Mon mon = {i,d,a};
if(mon.gain()>0) pos.push_back(mon);
else neg.push_back(mon);
}
sort(pos.begin(), pos.end(), cpos);
sort(neg.begin(), neg.end(), cneg);
for(Mon& mon: neg) pos.push_back(mon);
vi res;
for(Mon& mon: pos) {
//printf("# %lld %lld\n", hp, mon.d);
if(hp>mon.d) {
hp+=mon.gain();
res.push_back(mon.i);
}
else return vi();
}
return res;
}
int main() {
vi res = solve();
if(res.size()) {
puts("TAK");
for(auto i: res) printf("%d ", i);
puts("");
}
else puts("NIE");
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include <cstdio> #include <algorithm> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; struct Mon { ll i, d, a; ll gain() const {return a-d;} }; bool cpos(const Mon& x, const Mon& y) {return x.d < y.d;} bool cneg(const Mon& x, const Mon& y) {return x.a > y.a;} vi solve() { ll n, hp; scanf("%lld%lld", &n, &hp); vector<Mon> pos, neg; for(int i=1; i<=n; ++i) { ll d, a; scanf("%lld%lld", &d, &a); Mon mon = {i,d,a}; if(mon.gain()>0) pos.push_back(mon); else neg.push_back(mon); } sort(pos.begin(), pos.end(), cpos); sort(neg.begin(), neg.end(), cneg); for(Mon& mon: neg) pos.push_back(mon); vi res; for(Mon& mon: pos) { //printf("# %lld %lld\n", hp, mon.d); if(hp>mon.d) { hp+=mon.gain(); res.push_back(mon.i); } else return vi(); } return res; } int main() { vi res = solve(); if(res.size()) { puts("TAK"); for(auto i: res) printf("%d ", i); puts(""); } else puts("NIE"); } |
English