#include <stdlib.h> #include <stdio.h> #include <string.h> #include <vector> #include <algorithm> #include <list> using namespace std; class Monstrum { public: int i; int damage; int gain; }; bool compare_by_dmg_asc(Monstrum m1, Monstrum m2) { return m1.damage < m2.damage; } bool compare_by_dmg_desc(Monstrum m1, Monstrum m2) { return m2.damage < m1.damage; } int main() { int n; long long z; scanf("%d %lld", &n, &z); vector<Monstrum> monstra_plus; vector<Monstrum> monstra_minus; for (int i = 0; i < n; i++) { Monstrum m; int a; scanf("%d %d", &m.damage, &a); m.gain = a - m.damage; m.i = i + 1; if (m.gain >= 0) { monstra_plus.push_back(m); } else { monstra_minus.push_back(m); } } sort(monstra_plus.begin(), monstra_plus.end(), compare_by_dmg_asc); sort(monstra_minus.begin(), monstra_minus.end(), compare_by_dmg_desc); int kills = 0; vector<Monstrum>::iterator it = monstra_plus.begin(); while (kills < n) { long long dmg = it->damage; if (z - dmg > 0) { long long gain = it->gain; z += gain; kills++; // printf("%d. HP=%lld\n", kills, z); } else { printf("NIE\n"); return 0; } ++it; if (it == monstra_plus.end()) { it = monstra_minus.begin(); } } printf("TAK\n"); it = monstra_plus.begin(); while (it != monstra_minus.end()) { printf(it == monstra_plus.begin() ? "%d" : " %d", it->i); it++; if (it == monstra_plus.end()) { it = monstra_minus.begin(); } } printf("\n"); }
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 | #include <stdlib.h> #include <stdio.h> #include <string.h> #include <vector> #include <algorithm> #include <list> using namespace std; class Monstrum { public: int i; int damage; int gain; }; bool compare_by_dmg_asc(Monstrum m1, Monstrum m2) { return m1.damage < m2.damage; } bool compare_by_dmg_desc(Monstrum m1, Monstrum m2) { return m2.damage < m1.damage; } int main() { int n; long long z; scanf("%d %lld", &n, &z); vector<Monstrum> monstra_plus; vector<Monstrum> monstra_minus; for (int i = 0; i < n; i++) { Monstrum m; int a; scanf("%d %d", &m.damage, &a); m.gain = a - m.damage; m.i = i + 1; if (m.gain >= 0) { monstra_plus.push_back(m); } else { monstra_minus.push_back(m); } } sort(monstra_plus.begin(), monstra_plus.end(), compare_by_dmg_asc); sort(monstra_minus.begin(), monstra_minus.end(), compare_by_dmg_desc); int kills = 0; vector<Monstrum>::iterator it = monstra_plus.begin(); while (kills < n) { long long dmg = it->damage; if (z - dmg > 0) { long long gain = it->gain; z += gain; kills++; // printf("%d. HP=%lld\n", kills, z); } else { printf("NIE\n"); return 0; } ++it; if (it == monstra_plus.end()) { it = monstra_minus.begin(); } } printf("TAK\n"); it = monstra_plus.begin(); while (it != monstra_minus.end()) { printf(it == monstra_plus.begin() ? "%d" : " %d", it->i); it++; if (it == monstra_plus.end()) { it = monstra_minus.begin(); } } printf("\n"); } |