#include <cstdio> #include <utility> #include <set> using namespace std; #if (defined WIN32 || defined WINDOWS || defined _WIN32 || defined _WINDOWS) #define getchar_unlocked getchar #define putchar_unlocked putchar #endif typedef long long LL; int read_int() { register char c = 0; int result = 0; while (c < 33) c=getchar_unlocked(); while (c>32) {result=result*10 + (c-'0'); c=getchar_unlocked();} return result; } void write_int(int x) { if (x >= 10) write_int(x / 10); putchar_unlocked('0' + (x % 10)); } void write_newline() { putchar_unlocked('\n'); } void write_space() { putchar_unlocked(' '); } struct triplet { public: int i; int d; int a; }; struct loss_comparer { bool operator() (const triplet& lhs, const triplet& rhs) const { return lhs.d < rhs.d; } }; struct gain_comparer { bool operator() (const triplet& lhs, const triplet& rhs) const { return lhs.a > rhs.a; } }; int main() { int n = read_int(); LL z = read_int(); // first all battles where health is increasing starting from the battle with smallest loss // then we have maximum health // then all battles where health is deacrasing starting from the battle with highest gain multiset<triplet, loss_comparer> good_battles; multiset<triplet, gain_comparer> bad_battles; for (int i = 1; i <= n; ++i) { triplet t; t.i = i; t.d = read_int(); t.a = read_int(); if (t.a >= t.d) { good_battles.insert(t); } else { bad_battles.insert(t); } } for (multiset<triplet, loss_comparer>::iterator it = good_battles.begin(); it != good_battles.end(); ++it) { z -= it->d; if (z <= 0) { printf("NIE\n"); return 0; } z += it->a; } for (multiset<triplet, gain_comparer>::iterator it = bad_battles.begin(); it != bad_battles.end(); ++it) { z -= it->d; if (z <= 0) { printf("NIE\n"); return 0; } z += it->a; } printf("TAK\n"); for (multiset<triplet, loss_comparer>::iterator it = good_battles.begin(); it != good_battles.end(); ++it) { printf("%d ", it->i); } for (multiset<triplet, gain_comparer>::iterator it = bad_battles.begin(); it != bad_battles.end(); ++it) { printf("%d ", it->i); } printf("\n"); 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 109 110 111 112 113 114 | #include <cstdio> #include <utility> #include <set> using namespace std; #if (defined WIN32 || defined WINDOWS || defined _WIN32 || defined _WINDOWS) #define getchar_unlocked getchar #define putchar_unlocked putchar #endif typedef long long LL; int read_int() { register char c = 0; int result = 0; while (c < 33) c=getchar_unlocked(); while (c>32) {result=result*10 + (c-'0'); c=getchar_unlocked();} return result; } void write_int(int x) { if (x >= 10) write_int(x / 10); putchar_unlocked('0' + (x % 10)); } void write_newline() { putchar_unlocked('\n'); } void write_space() { putchar_unlocked(' '); } struct triplet { public: int i; int d; int a; }; struct loss_comparer { bool operator() (const triplet& lhs, const triplet& rhs) const { return lhs.d < rhs.d; } }; struct gain_comparer { bool operator() (const triplet& lhs, const triplet& rhs) const { return lhs.a > rhs.a; } }; int main() { int n = read_int(); LL z = read_int(); // first all battles where health is increasing starting from the battle with smallest loss // then we have maximum health // then all battles where health is deacrasing starting from the battle with highest gain multiset<triplet, loss_comparer> good_battles; multiset<triplet, gain_comparer> bad_battles; for (int i = 1; i <= n; ++i) { triplet t; t.i = i; t.d = read_int(); t.a = read_int(); if (t.a >= t.d) { good_battles.insert(t); } else { bad_battles.insert(t); } } for (multiset<triplet, loss_comparer>::iterator it = good_battles.begin(); it != good_battles.end(); ++it) { z -= it->d; if (z <= 0) { printf("NIE\n"); return 0; } z += it->a; } for (multiset<triplet, gain_comparer>::iterator it = bad_battles.begin(); it != bad_battles.end(); ++it) { z -= it->d; if (z <= 0) { printf("NIE\n"); return 0; } z += it->a; } printf("TAK\n"); for (multiset<triplet, loss_comparer>::iterator it = good_battles.begin(); it != good_battles.end(); ++it) { printf("%d ", it->i); } for (multiset<triplet, gain_comparer>::iterator it = bad_battles.begin(); it != bad_battles.end(); ++it) { printf("%d ", it->i); } printf("\n"); return 0; } |