# include <cstdio> # include <algorithm> # define SIZE 100000 using namespace std; pair <pair <int, int>, int> monsters[100000]; # define dur first.first # define ref first.second bool cmp(pair <pair <int, int>, int> a, pair <pair <int, int>, int> b) { if (a.ref>=a.dur && b.ref<b.dur) return true; if (b.ref>=b.dur && a.ref<a.dur) return false; if (a.ref>=a.dur) return a.dur<b.dur; return a.ref>b.ref; } int main() { int n, z; scanf("%d%d", &n, &z); for (int i=0; i<n; ++i) { int x, y; scanf("%d%d", &x, &y); monsters[i]=make_pair(make_pair(x, y), i+1); } sort(monsters, monsters+n, cmp); for (int i=0; i<n; ++i) { if (monsters[i].dur>=z) { printf("NIE\n"); return 0; } z+=monsters[i].ref-monsters[i].dur; } printf("TAK\n"); for (int i=0; i<n; ++i) printf("%d ", monsters[i].second); printf("\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 | # include <cstdio> # include <algorithm> # define SIZE 100000 using namespace std; pair <pair <int, int>, int> monsters[100000]; # define dur first.first # define ref first.second bool cmp(pair <pair <int, int>, int> a, pair <pair <int, int>, int> b) { if (a.ref>=a.dur && b.ref<b.dur) return true; if (b.ref>=b.dur && a.ref<a.dur) return false; if (a.ref>=a.dur) return a.dur<b.dur; return a.ref>b.ref; } int main() { int n, z; scanf("%d%d", &n, &z); for (int i=0; i<n; ++i) { int x, y; scanf("%d%d", &x, &y); monsters[i]=make_pair(make_pair(x, y), i+1); } sort(monsters, monsters+n, cmp); for (int i=0; i<n; ++i) { if (monsters[i].dur>=z) { printf("NIE\n"); return 0; } z+=monsters[i].ref-monsters[i].dur; } printf("TAK\n"); for (int i=0; i<n; ++i) printf("%d ", monsters[i].second); printf("\n"); } |