#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct monster
{
int dmg, heal, id;
monster(int a=0, int b=0, int c=0): dmg(a), heal(b), id(c) {}
};
bool cmp(monster a, monster b)
{
return a.dmg<b.dmg;
}
bool cmp2(monster a, monster b)
{
return a.heal<b.heal;
}
vector<monster> prof, loss;
int hp,n,a,b,thp;
int main()
{
scanf("%d%d", &n, &hp);
for(int i=0; i<n; i++)
{
scanf("%d%d", &a, &b);
if(a<=b)
prof.push_back(monster(a,b,i+1));
else
loss.push_back(monster(a,b,i+1));
}
sort(prof.begin(), prof.end(), cmp);
sort(loss.begin(), loss.end(), cmp2);
for(int i=0; i<prof.size(); i++)
{
if(prof[i].dmg>=hp){ printf("NIE\n"); return 0;}
hp+=prof[i].heal-prof[i].dmg;
}
for(int i=0; i<loss.size(); i++)
{
thp-=loss[i].heal;
if(thp<=0) thp=1;
thp+=loss[i].dmg;
}
if(thp<=hp)
{
printf("TAK\n");
for(int i=0; i<prof.size(); i++)
printf("%d ", prof[i].id);
for(int i=loss.size()-1; i>=0; i--)
printf("%d ", loss[i].id);
}
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 | #include <cstdio> #include <vector> #include <algorithm> using namespace std; struct monster { int dmg, heal, id; monster(int a=0, int b=0, int c=0): dmg(a), heal(b), id(c) {} }; bool cmp(monster a, monster b) { return a.dmg<b.dmg; } bool cmp2(monster a, monster b) { return a.heal<b.heal; } vector<monster> prof, loss; int hp,n,a,b,thp; int main() { scanf("%d%d", &n, &hp); for(int i=0; i<n; i++) { scanf("%d%d", &a, &b); if(a<=b) prof.push_back(monster(a,b,i+1)); else loss.push_back(monster(a,b,i+1)); } sort(prof.begin(), prof.end(), cmp); sort(loss.begin(), loss.end(), cmp2); for(int i=0; i<prof.size(); i++) { if(prof[i].dmg>=hp){ printf("NIE\n"); return 0;} hp+=prof[i].heal-prof[i].dmg; } for(int i=0; i<loss.size(); i++) { thp-=loss[i].heal; if(thp<=0) thp=1; thp+=loss[i].dmg; } if(thp<=hp) { printf("TAK\n"); for(int i=0; i<prof.size(); i++) printf("%d ", prof[i].id); for(int i=loss.size()-1; i>=0; i--) printf("%d ", loss[i].id); } else printf("NIE\n"); } |
English