#include <stdio.h> #include <algorithm> class Monster { public: int power; int gain; int LP; bool operator< (const Monster &arg) const { if(gain < 0 && arg.gain >= 0) return false; else if(gain >= 0 && arg.gain < 0) return true; else if(gain < 0 && arg.gain < 0) { if(power == arg.power) return gain >= arg.gain; else return power > arg.power; } else { if(power == arg.power) return gain >= arg.gain; else return power < arg.power; } } }; int main() { Monster tab[100001]; int n, HP; scanf("%i %i", &n, &HP); for(int i = 0; i < n; ++i) { Monster monster; scanf("%i %i", &(monster.power), &(monster.gain)); monster.gain -= monster.power; monster.LP = i+1; //printf("%i %i %i\n", monster.power, monster.gain, monster.LP); tab[i] = monster; } std::sort(tab, tab+n); bool possible = true; for(int i = 0; i < n; ++i) { if(tab[i].power >= HP) possible = false; HP += tab[i].gain; if(HP <= 0) possible = false; } if(possible) { printf("TAK\n"); for(int i = 0; i < n; ++i) { printf("%i ", tab[i].LP); } printf("\n"); } else printf("NIE\n"); 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 | #include <stdio.h> #include <algorithm> class Monster { public: int power; int gain; int LP; bool operator< (const Monster &arg) const { if(gain < 0 && arg.gain >= 0) return false; else if(gain >= 0 && arg.gain < 0) return true; else if(gain < 0 && arg.gain < 0) { if(power == arg.power) return gain >= arg.gain; else return power > arg.power; } else { if(power == arg.power) return gain >= arg.gain; else return power < arg.power; } } }; int main() { Monster tab[100001]; int n, HP; scanf("%i %i", &n, &HP); for(int i = 0; i < n; ++i) { Monster monster; scanf("%i %i", &(monster.power), &(monster.gain)); monster.gain -= monster.power; monster.LP = i+1; //printf("%i %i %i\n", monster.power, monster.gain, monster.LP); tab[i] = monster; } std::sort(tab, tab+n); bool possible = true; for(int i = 0; i < n; ++i) { if(tab[i].power >= HP) possible = false; HP += tab[i].gain; if(HP <= 0) possible = false; } if(possible) { printf("TAK\n"); for(int i = 0; i < n; ++i) { printf("%i ", tab[i].LP); } printf("\n"); } else printf("NIE\n"); return 0; } |