#include <cstdio> #include <vector> #include <map> #include <algorithm> #include <set> #include <deque> #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) using namespace std; struct fight { long long monster, potion; int id; void get(int i) { id = i; scanf("%lld %lld", &monster, &potion); } }; bool cmp_positive(const fight& x, const fight& y) { if (x.monster != y.monster) return x.monster < y.monster; return x.potion < y.potion; } bool cmp_negative(const fight& x, const fight& y) { if (x.potion != y.potion) return x.potion > y.potion; return x.monster > y.monster; } void verify(vector<fight>& a, vector<fight>& b, long long hp) { REP(i, a.size()) { if (hp <= a[i].monster) { printf("ZLE!\n"); return; } hp = hp - a[i].monster + a[i].potion; } REP(i, b.size()) { if (hp <= b[i].monster) { printf("ZLE!\n"); return; } hp = hp - b[i].monster + b[i].potion; } } int main() { int n; long long hp; scanf("%d %lld", &n, &hp); long long ohp = hp; vector<fight> positive, negative; REP(i, n) { fight f; f.get(i+1); if (f.potion >= f.monster) { positive.push_back(f); } else { negative.push_back(f); } } // First positive sort(positive.begin(), positive.end(), cmp_positive); REP(i, positive.size()) { if (hp <= positive[i].monster) { printf("NIE\n"); return 0; } hp += positive[i].potion - positive[i].monster; } // printf("po positive hp = %lld\n", hp); // Negative long long dhp = 0; REP(i, negative.size()) { dhp = dhp - negative[i].monster + negative[i].potion; } // printf("dhp = %lld\n", dhp); if (hp + dhp <= 0) { printf("NIE\n"); return 0; } sort(negative.begin(), negative.end(), cmp_negative); REP(i, negative.size()) { if (hp <= negative[i].monster) { printf("NIE\n"); return 0; } hp = hp - negative[i].monster + negative[i].potion; } printf("TAK\n"); REP(i, positive.size()) printf("%d ", positive[i].id); REP(i, negative.size()) printf("%d ", negative[i].id); printf("\n"); // verify(positive, negative, ohp); return 0; }
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | #include <cstdio> #include <vector> #include <map> #include <algorithm> #include <set> #include <deque> #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) using namespace std; struct fight { long long monster, potion; int id; void get(int i) { id = i; scanf("%lld %lld", &monster, &potion); } }; bool cmp_positive(const fight& x, const fight& y) { if (x.monster != y.monster) return x.monster < y.monster; return x.potion < y.potion; } bool cmp_negative(const fight& x, const fight& y) { if (x.potion != y.potion) return x.potion > y.potion; return x.monster > y.monster; } void verify(vector<fight>& a, vector<fight>& b, long long hp) { REP(i, a.size()) { if (hp <= a[i].monster) { printf("ZLE!\n"); return; } hp = hp - a[i].monster + a[i].potion; } REP(i, b.size()) { if (hp <= b[i].monster) { printf("ZLE!\n"); return; } hp = hp - b[i].monster + b[i].potion; } } int main() { int n; long long hp; scanf("%d %lld", &n, &hp); long long ohp = hp; vector<fight> positive, negative; REP(i, n) { fight f; f.get(i+1); if (f.potion >= f.monster) { positive.push_back(f); } else { negative.push_back(f); } } // First positive sort(positive.begin(), positive.end(), cmp_positive); REP(i, positive.size()) { if (hp <= positive[i].monster) { printf("NIE\n"); return 0; } hp += positive[i].potion - positive[i].monster; } // printf("po positive hp = %lld\n", hp); // Negative long long dhp = 0; REP(i, negative.size()) { dhp = dhp - negative[i].monster + negative[i].potion; } // printf("dhp = %lld\n", dhp); if (hp + dhp <= 0) { printf("NIE\n"); return 0; } sort(negative.begin(), negative.end(), cmp_negative); REP(i, negative.size()) { if (hp <= negative[i].monster) { printf("NIE\n"); return 0; } hp = hp - negative[i].monster + negative[i].potion; } printf("TAK\n"); REP(i, positive.size()) printf("%d ", positive[i].id); REP(i, negative.size()) printf("%d ", negative[i].id); printf("\n"); // verify(positive, negative, ohp); return 0; } |