#include <cstdio> #include <algorithm> #include <vector> #define PB push_back using namespace std; typedef long long LL; struct str { int dmg, rec, id; }; int n; LL hp; str pom; vector<str> v1, v2; bool cmp1 (str x, str y) { return x.dmg < y.dmg; } bool cmp2 (str x, str y) { return x.dmg > y.dmg; } int main () { scanf ("%d%lld", &n, &hp); for (int i = 1; i <= n; ++i) { scanf ("%d%d", &pom.dmg, &pom.rec); pom.id = i; if (pom.rec >= pom.dmg) v1.PB(pom); else v2.PB(pom); } sort(v1.begin(), v1.end(), cmp1); sort(v2.begin(), v2.end(), cmp2); for (int i = 0; i < (int)v1.size(); ++i) { if (v1[i].dmg >= hp) { printf ("NIE\n"); return 0; } hp -= (v1[i].dmg - v1[i].rec); } for (int i = 0; i < (int)v2.size(); ++i) { if (v2[i].dmg >= hp) { printf ("NIE\n"); return 0; } hp -= (v2[i].dmg - v2[i].rec); } printf ("TAK\n"); for (int i = 0; i < v1.size(); ++i) printf ("%d ", v1[i].id); for (int i = 0; i < v2.size(); ++i) printf ("%d ", v2[i].id); 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 | #include <cstdio> #include <algorithm> #include <vector> #define PB push_back using namespace std; typedef long long LL; struct str { int dmg, rec, id; }; int n; LL hp; str pom; vector<str> v1, v2; bool cmp1 (str x, str y) { return x.dmg < y.dmg; } bool cmp2 (str x, str y) { return x.dmg > y.dmg; } int main () { scanf ("%d%lld", &n, &hp); for (int i = 1; i <= n; ++i) { scanf ("%d%d", &pom.dmg, &pom.rec); pom.id = i; if (pom.rec >= pom.dmg) v1.PB(pom); else v2.PB(pom); } sort(v1.begin(), v1.end(), cmp1); sort(v2.begin(), v2.end(), cmp2); for (int i = 0; i < (int)v1.size(); ++i) { if (v1[i].dmg >= hp) { printf ("NIE\n"); return 0; } hp -= (v1[i].dmg - v1[i].rec); } for (int i = 0; i < (int)v2.size(); ++i) { if (v2[i].dmg >= hp) { printf ("NIE\n"); return 0; } hp -= (v2[i].dmg - v2[i].rec); } printf ("TAK\n"); for (int i = 0; i < v1.size(); ++i) printf ("%d ", v1[i].id); for (int i = 0; i < v2.size(); ++i) printf ("%d ", v2[i].id); return 0; } |