#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
struct Potwor {
int bonusHp, damage, index;
};
bool compare(Potwor a, Potwor b){
if(a.bonusHp-a.damage < 0 == b.bonusHp-b.damage < 0){
if(a.bonusHp-a.damage>=0){
return a.damage < b.damage;
} else {
return a.bonusHp > b.bonusHp;
}
} else {
if(a.bonusHp-a.damage <0)return false;
return true;
}
return a.bonusHp-a.damage > b.bonusHp-b.damage;
}
bool check(vector<Potwor> monsters, int startHp){
int hp = startHp;
for(int x=0; x<monsters.size(); x++){
hp -= monsters[x].damage;
if(hp <= 0)return false;
hp += monsters[x].bonusHp;
}
return true;
}
int main(){
int monsters, hp;
scanf("%d %d", &monsters, &hp);
vector<Potwor> potwory;
int damage, bonusHp;
Potwor last;
scanf("%d %d", &damage, &bonusHp);
last.damage = damage;
last.bonusHp = bonusHp;
last.index = 1;
for(int x=1; x<monsters; x++){
scanf("%d %d", &damage, &bonusHp);
if(bonusHp < last.bonusHp || (bonusHp==last.bonusHp && damage < last.damage) ){
potwory.push_back(last);
last.damage = damage;
last.bonusHp = bonusHp;
last.index = x+1;
}
else {
Potwor a;
a.damage = damage;
a.bonusHp = bonusHp;
a.index = x+1;
potwory.push_back(a);
}
}
sort(potwory.begin(), potwory.end(), compare);
potwory.push_back(last);
if(check(potwory, hp)){
printf("TAK\n");
for(int x=0; x<monsters; x++){
printf("%d ", potwory[x].index);
}
printf("\n");
} else {
printf("NIE\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 <stdio.h> #include <algorithm> #include <vector> using namespace std; struct Potwor { int bonusHp, damage, index; }; bool compare(Potwor a, Potwor b){ if(a.bonusHp-a.damage < 0 == b.bonusHp-b.damage < 0){ if(a.bonusHp-a.damage>=0){ return a.damage < b.damage; } else { return a.bonusHp > b.bonusHp; } } else { if(a.bonusHp-a.damage <0)return false; return true; } return a.bonusHp-a.damage > b.bonusHp-b.damage; } bool check(vector<Potwor> monsters, int startHp){ int hp = startHp; for(int x=0; x<monsters.size(); x++){ hp -= monsters[x].damage; if(hp <= 0)return false; hp += monsters[x].bonusHp; } return true; } int main(){ int monsters, hp; scanf("%d %d", &monsters, &hp); vector<Potwor> potwory; int damage, bonusHp; Potwor last; scanf("%d %d", &damage, &bonusHp); last.damage = damage; last.bonusHp = bonusHp; last.index = 1; for(int x=1; x<monsters; x++){ scanf("%d %d", &damage, &bonusHp); if(bonusHp < last.bonusHp || (bonusHp==last.bonusHp && damage < last.damage) ){ potwory.push_back(last); last.damage = damage; last.bonusHp = bonusHp; last.index = x+1; } else { Potwor a; a.damage = damage; a.bonusHp = bonusHp; a.index = x+1; potwory.push_back(a); } } sort(potwory.begin(), potwory.end(), compare); potwory.push_back(last); if(check(potwory, hp)){ printf("TAK\n"); for(int x=0; x<monsters; x++){ printf("%d ", potwory[x].index); } printf("\n"); } else { printf("NIE\n"); } } |
English