#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
struct monster{
int dmg, hpRecovery, index;
monster();
monster(int);
};
monster::monster(){}
monster::monster(int i){
index = i;
cin >> dmg >> hpRecovery;
}
bool sortByHpRecovery(monster mOne, monster mTwo){
if (mOne.hpRecovery != mTwo.hpRecovery) return mOne.hpRecovery > mTwo.hpRecovery;
return mOne.dmg > mTwo.dmg;
}
int main(){
ios_base::sync_with_stdio(0);
list<monster> monsters;
int amount, heroHp;
cin >> amount >> heroHp;
for (int i = 1; i <= amount; i++)
monsters.push_back(monster(i));
monsters.sort(sortByHpRecovery);
int j = 0;
for (list<monster>::iterator it = monsters.begin(); it != monsters.end(); it++){
if (heroHp <= it->dmg && j != amount - 1){
bool canYouWin = false;
for (list<monster>::iterator it2 = it; it2 != monsters.end(); it2++)
if (it2->dmg < heroHp){
canYouWin = true;
monsters.splice(monsters.begin(), monsters, it2);
break;
}
if (!canYouWin) heroHp = 0;
}
else heroHp -= it->dmg;
if (heroHp <= 0){
cout << "NIE";
break;
}
heroHp += it->hpRecovery;
++j;
}
if (heroHp > 0){
cout << "TAK" << endl;
for (list<monster>::iterator it = monsters.begin(); it != monsters.end(); it++)
cout << it->index << " ";
}
}
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 | #include <iostream> #include <list> #include <algorithm> using namespace std; struct monster{ int dmg, hpRecovery, index; monster(); monster(int); }; monster::monster(){} monster::monster(int i){ index = i; cin >> dmg >> hpRecovery; } bool sortByHpRecovery(monster mOne, monster mTwo){ if (mOne.hpRecovery != mTwo.hpRecovery) return mOne.hpRecovery > mTwo.hpRecovery; return mOne.dmg > mTwo.dmg; } int main(){ ios_base::sync_with_stdio(0); list<monster> monsters; int amount, heroHp; cin >> amount >> heroHp; for (int i = 1; i <= amount; i++) monsters.push_back(monster(i)); monsters.sort(sortByHpRecovery); int j = 0; for (list<monster>::iterator it = monsters.begin(); it != monsters.end(); it++){ if (heroHp <= it->dmg && j != amount - 1){ bool canYouWin = false; for (list<monster>::iterator it2 = it; it2 != monsters.end(); it2++) if (it2->dmg < heroHp){ canYouWin = true; monsters.splice(monsters.begin(), monsters, it2); break; } if (!canYouWin) heroHp = 0; } else heroHp -= it->dmg; if (heroHp <= 0){ cout << "NIE"; break; } heroHp += it->hpRecovery; ++j; } if (heroHp > 0){ cout << "TAK" << endl; for (list<monster>::iterator it = monsters.begin(); it != monsters.end(); it++) cout << it->index << " "; } } |
English