#include <cstdio> #include <vector> #include <list> #include <algorithm> #include <iostream> #include <utility> #include <cassert> using namespace std; struct monster { int id; int damage; int regen; bool operator<(const monster& other) const { return regen - damage > other.regen - other.damage; } }; bool dmgsort(const monster& a, const monster&b) { return a.damage < b.damage; } bool revdmgsort(const monster& a, const monster& b) { return a.damage > b.damage; } bool reverseregensort(const monster& a, const monster& b) { return a.regen > b.regen; } int main() { int n, z; scanf("%d%d", &n, &z); int Z = z; vector<monster> monsters(n); for (int i = 0; i < n; ++i) { int l, h; scanf("%d%d", &l, &h); monster mm = {i+1, l, h}; monsters[i] = mm; } sort(monsters.begin(), monsters.end()); int idx = 0; int idx2 = 0; while (idx < n && monsters[idx].regen - monsters[idx].damage > 0) { idx++; idx2++; } while (idx2 < n && monsters[idx2].regen - monsters[idx2].damage == 0) idx2++; sort(monsters.begin(), monsters.begin()+idx, dmgsort); sort(monsters.begin()+idx2, monsters.end(), reverseregensort); vector<int> bt(n); for (int i = 0; i < n; ++i) { if (z <= monsters[i].damage) { printf("NIE\n"); return 0; } z += monsters[i].regen - monsters[i].damage; bt[i] = monsters[i].id; } printf("TAK\n"); for (int i = 0; i < n; ++i) printf("%d ", bt[i]); printf("\n"); ////TESTER // for (int i = 0; i < n; ++i) { // cout << i << " " << monsters[i].damage << " " << monsters[i].regen << " " << Z << endl; // assert(Z - monsters[i].damage > 0); // Z += monsters[i].regen - monsters[i].damage; // } 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 | #include <cstdio> #include <vector> #include <list> #include <algorithm> #include <iostream> #include <utility> #include <cassert> using namespace std; struct monster { int id; int damage; int regen; bool operator<(const monster& other) const { return regen - damage > other.regen - other.damage; } }; bool dmgsort(const monster& a, const monster&b) { return a.damage < b.damage; } bool revdmgsort(const monster& a, const monster& b) { return a.damage > b.damage; } bool reverseregensort(const monster& a, const monster& b) { return a.regen > b.regen; } int main() { int n, z; scanf("%d%d", &n, &z); int Z = z; vector<monster> monsters(n); for (int i = 0; i < n; ++i) { int l, h; scanf("%d%d", &l, &h); monster mm = {i+1, l, h}; monsters[i] = mm; } sort(monsters.begin(), monsters.end()); int idx = 0; int idx2 = 0; while (idx < n && monsters[idx].regen - monsters[idx].damage > 0) { idx++; idx2++; } while (idx2 < n && monsters[idx2].regen - monsters[idx2].damage == 0) idx2++; sort(monsters.begin(), monsters.begin()+idx, dmgsort); sort(monsters.begin()+idx2, monsters.end(), reverseregensort); vector<int> bt(n); for (int i = 0; i < n; ++i) { if (z <= monsters[i].damage) { printf("NIE\n"); return 0; } z += monsters[i].regen - monsters[i].damage; bt[i] = monsters[i].id; } printf("TAK\n"); for (int i = 0; i < n; ++i) printf("%d ", bt[i]); printf("\n"); ////TESTER // for (int i = 0; i < n; ++i) { // cout << i << " " << monsters[i].damage << " " << monsters[i].regen << " " << Z << endl; // assert(Z - monsters[i].damage > 0); // Z += monsters[i].regen - monsters[i].damage; // } return 0; } |