#include <cstdio> #include <vector> #include <algorithm> using namespace std; struct monster { int index; int damage; int heal; }; int life; vector<monster> monsters; vector<int> encounters; template <typename Pred> bool fight_if(Pred pred) { for (const monster& m : monsters) { if (pred(m)) { if (m.damage < life) { encounters.push_back(m.index); life += m.heal - m.damage; } else { return false; } } } return true; } int main() { int n; scanf("%i %i", &n, &life); for (int i = 0; i < n; ++i) { monster m; m.index = i + 1; scanf("%i %i", &m.damage, &m.heal); monsters.emplace_back(m); } sort(monsters.begin(), monsters.end(), [] (const monster& a, const monster& b) { return a.damage < b.damage; }); if (!fight_if([] (const monster& m) -> bool { return m.heal - m.damage >= 0; })) { puts("NIE"); return 0; } reverse(monsters.begin(), monsters.end()); if (!fight_if([] (const monster& m) -> bool { return m.heal - m.damage < 0; })) { puts("NIE"); return 0; } puts("TAK"); for (int i : encounters) { printf("%i ", i); } 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 | #include <cstdio> #include <vector> #include <algorithm> using namespace std; struct monster { int index; int damage; int heal; }; int life; vector<monster> monsters; vector<int> encounters; template <typename Pred> bool fight_if(Pred pred) { for (const monster& m : monsters) { if (pred(m)) { if (m.damage < life) { encounters.push_back(m.index); life += m.heal - m.damage; } else { return false; } } } return true; } int main() { int n; scanf("%i %i", &n, &life); for (int i = 0; i < n; ++i) { monster m; m.index = i + 1; scanf("%i %i", &m.damage, &m.heal); monsters.emplace_back(m); } sort(monsters.begin(), monsters.end(), [] (const monster& a, const monster& b) { return a.damage < b.damage; }); if (!fight_if([] (const monster& m) -> bool { return m.heal - m.damage >= 0; })) { puts("NIE"); return 0; } reverse(monsters.begin(), monsters.end()); if (!fight_if([] (const monster& m) -> bool { return m.heal - m.damage < 0; })) { puts("NIE"); return 0; } puts("TAK"); for (int i : encounters) { printf("%i ", i); } return 0; } |