#include <cstdio> #include <algorithm> #define MAX_N 100000 struct monster { int dmg; int potion; int num; }; bool sort_dmg(struct monster a, struct monster b) { return a.dmg < b.dmg; } bool sort_potion(struct monster a, struct monster b) { return a.potion < b.potion; } int main() { int n, d, a; long long life, taken = 0; struct monster inc[MAX_N], dec[MAX_N]; int inc_size = 0, dec_size = 0; int path[MAX_N]; scanf("%d %lld", &n, &life); for (int i = 0; i < n; i++) { scanf("%d %d", &d, &a); if (d > a) { dec[dec_size].dmg = d; dec[dec_size].potion = a; dec[dec_size].num = i; dec_size++; taken += (d - a); } else { inc[inc_size].dmg = d; inc[inc_size].potion = a; inc[inc_size].num = i; inc_size++; } } std::sort(inc, inc + inc_size, sort_dmg); std::sort(dec, dec + dec_size, sort_potion); for (int i = 0; i < inc_size; i++) { life -= inc[i].dmg; if (life <= 0) break; life += inc[i].potion; path[i] = inc[i].num; } life -= taken; for (int i = 0; i < dec_size; i++) { life -= dec[i].potion; if (life <= 0) break; life += dec[i].dmg; path[n-i-1] = dec[i].num; } if (life <= 0) printf("NIE\n"); else { printf("TAK\n"); for (int i = 0; i < n - 1; i++) printf("%d ", path[i] + 1); printf("%d\n", path[n-1] + 1); } 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 | #include <cstdio> #include <algorithm> #define MAX_N 100000 struct monster { int dmg; int potion; int num; }; bool sort_dmg(struct monster a, struct monster b) { return a.dmg < b.dmg; } bool sort_potion(struct monster a, struct monster b) { return a.potion < b.potion; } int main() { int n, d, a; long long life, taken = 0; struct monster inc[MAX_N], dec[MAX_N]; int inc_size = 0, dec_size = 0; int path[MAX_N]; scanf("%d %lld", &n, &life); for (int i = 0; i < n; i++) { scanf("%d %d", &d, &a); if (d > a) { dec[dec_size].dmg = d; dec[dec_size].potion = a; dec[dec_size].num = i; dec_size++; taken += (d - a); } else { inc[inc_size].dmg = d; inc[inc_size].potion = a; inc[inc_size].num = i; inc_size++; } } std::sort(inc, inc + inc_size, sort_dmg); std::sort(dec, dec + dec_size, sort_potion); for (int i = 0; i < inc_size; i++) { life -= inc[i].dmg; if (life <= 0) break; life += inc[i].potion; path[i] = inc[i].num; } life -= taken; for (int i = 0; i < dec_size; i++) { life -= dec[i].potion; if (life <= 0) break; life += dec[i].dmg; path[n-i-1] = dec[i].num; } if (life <= 0) printf("NIE\n"); else { printf("TAK\n"); for (int i = 0; i < n - 1; i++) printf("%d ", path[i] + 1); printf("%d\n", path[n-1] + 1); } return 0; } |