#include <stdio.h> #include <algorithm> // std::sort #include <vector> using namespace std; class Monster{ public: int nr; int delta; int dmg; void print(); }; void Monster::print() { printf("nr=%d, d=%d, dmg=%d\n", nr, delta, dmg); } bool compMonstersDmg (Monster m1,Monster m2) { return (m1.dmg<m2.dmg); } bool compMonstersDelta (Monster m1,Monster m2) { return (m1.delta>m2.delta); } int main() { int n, z; int dmg, heal, delta; vector<Monster> hardOponents; vector<Monster> easyOponents; scanf("%d %d", &n, &z); int sumDelta = z; for (int i=1; i<=n; ++i){ scanf("%d %d", &dmg, &heal); delta = heal - dmg; sumDelta += delta; Monster monster; monster.delta = delta; monster.nr = i; monster.dmg = dmg; if (delta > 0) easyOponents.push_back(monster); else hardOponents.push_back(monster); } bool canSucceed = true; if (sumDelta <= 0) canSucceed = false; // using default comparison (operator <): if (canSucceed) { std::sort (easyOponents.begin(), easyOponents.end(), compMonstersDmg); std::sort (hardOponents.begin(), hardOponents.end(), compMonstersDelta); /*for (int i=0; i<easyOponents.size(); ++i) easyOponents[i].print(); printf("\n"); for (int i=0; i<hardOponents.size(); ++i) hardOponents[i].print();*/ int curHP = z; for (int i=0; i<easyOponents.size(); ++i){ if (curHP - easyOponents[i].dmg <= 0 ){ canSucceed = false; break; } } } if (!canSucceed){ printf("NIE\n"); return 0; } else { printf("TAK\n"); for (int i=0; i<easyOponents.size(); ++i) printf("%d ", easyOponents[i].nr); for (int i=0; i<hardOponents.size(); ++i) printf("%d ", hardOponents[i].nr); } }
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 | #include <stdio.h> #include <algorithm> // std::sort #include <vector> using namespace std; class Monster{ public: int nr; int delta; int dmg; void print(); }; void Monster::print() { printf("nr=%d, d=%d, dmg=%d\n", nr, delta, dmg); } bool compMonstersDmg (Monster m1,Monster m2) { return (m1.dmg<m2.dmg); } bool compMonstersDelta (Monster m1,Monster m2) { return (m1.delta>m2.delta); } int main() { int n, z; int dmg, heal, delta; vector<Monster> hardOponents; vector<Monster> easyOponents; scanf("%d %d", &n, &z); int sumDelta = z; for (int i=1; i<=n; ++i){ scanf("%d %d", &dmg, &heal); delta = heal - dmg; sumDelta += delta; Monster monster; monster.delta = delta; monster.nr = i; monster.dmg = dmg; if (delta > 0) easyOponents.push_back(monster); else hardOponents.push_back(monster); } bool canSucceed = true; if (sumDelta <= 0) canSucceed = false; // using default comparison (operator <): if (canSucceed) { std::sort (easyOponents.begin(), easyOponents.end(), compMonstersDmg); std::sort (hardOponents.begin(), hardOponents.end(), compMonstersDelta); /*for (int i=0; i<easyOponents.size(); ++i) easyOponents[i].print(); printf("\n"); for (int i=0; i<hardOponents.size(); ++i) hardOponents[i].print();*/ int curHP = z; for (int i=0; i<easyOponents.size(); ++i){ if (curHP - easyOponents[i].dmg <= 0 ){ canSucceed = false; break; } } } if (!canSucceed){ printf("NIE\n"); return 0; } else { printf("TAK\n"); for (int i=0; i<easyOponents.size(); ++i) printf("%d ", easyOponents[i].nr); for (int i=0; i<hardOponents.size(); ++i) printf("%d ", hardOponents[i].nr); } } |