/*
* dawid.sieradzki@gmail.com
*/
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX_N = 100100;
struct Monster {
int d, a;
int idx;
} t[MAX_N];
bool operator <(const Monster &a, const Monster &b) {
long long d1 = a.a - a.d;
long long d2 = b.a - b.d;
if (d1 * d2 <= 0) {
return d2 < d1;
}
if (d1 >= 0 && d2 >= 0) {
if (a.d != b.d) {
return a.d < b.d;
}
} else {
if (a.d != b.d) {
return a.d > b.d;
}
}
return a.idx < b.idx;
}
int n;
long long z;
int main(int argc, char *argv[]) {
scanf("%i%lli", &n, &z);
for (int c = 0; c < n; c++) {
scanf("%i%i", &t[c].d, &t[c].a);
t[c].idx = c + 1;
}
sort(t, t + n);
bool ret = true;
for (int c = 0; ret && c < n; c++) {
ret = ((z -= t[c].d) > 0);
z += t[c].a;
}
printf(ret ? "TAK\n" : "NIE\n");
if (ret) {
for (int c = 0; c < n; c++) {
printf("%i ", t[c].idx);
}
printf("\n");
}
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 | /* * dawid.sieradzki@gmail.com */ #include <cstdio> #include <algorithm> using namespace std; const int MAX_N = 100100; struct Monster { int d, a; int idx; } t[MAX_N]; bool operator <(const Monster &a, const Monster &b) { long long d1 = a.a - a.d; long long d2 = b.a - b.d; if (d1 * d2 <= 0) { return d2 < d1; } if (d1 >= 0 && d2 >= 0) { if (a.d != b.d) { return a.d < b.d; } } else { if (a.d != b.d) { return a.d > b.d; } } return a.idx < b.idx; } int n; long long z; int main(int argc, char *argv[]) { scanf("%i%lli", &n, &z); for (int c = 0; c < n; c++) { scanf("%i%i", &t[c].d, &t[c].a); t[c].idx = c + 1; } sort(t, t + n); bool ret = true; for (int c = 0; ret && c < n; c++) { ret = ((z -= t[c].d) > 0); z += t[c].a; } printf(ret ? "TAK\n" : "NIE\n"); if (ret) { for (int c = 0; c < n; c++) { printf("%i ", t[c].idx); } printf("\n"); } return 0; } |
English