#include <algorithm> #include <cstdio> using namespace std; #define REP(i,n) for (int i = 0; i < (n); ++i) typedef long long LL; const int INF = 1000000000; struct P { int i, d, a; int v() const { if (d < a) return d-INF; if (d > a) return INF-a; return 0; } }; bool operator<(const P& p1, const P& p2) { return p1.v() < p2.v(); } P p[100000]; int main() { int n; LL z; scanf("%d%lld", &n, &z); REP(i,n) { p[i].i = i + 1; scanf("%d%d", &p[i].d, &p[i].a); } sort(p, p + n); REP(i,n) { z -= p[i].d; if (z <= 0) { printf("NIE\n"); return 0; } z += p[i].a; } printf("TAK\n"); REP(i,n) { if (i) printf(" "); printf("%d", p[i].i); } 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 43 44 45 46 47 | #include <algorithm> #include <cstdio> using namespace std; #define REP(i,n) for (int i = 0; i < (n); ++i) typedef long long LL; const int INF = 1000000000; struct P { int i, d, a; int v() const { if (d < a) return d-INF; if (d > a) return INF-a; return 0; } }; bool operator<(const P& p1, const P& p2) { return p1.v() < p2.v(); } P p[100000]; int main() { int n; LL z; scanf("%d%lld", &n, &z); REP(i,n) { p[i].i = i + 1; scanf("%d%d", &p[i].d, &p[i].a); } sort(p, p + n); REP(i,n) { z -= p[i].d; if (z <= 0) { printf("NIE\n"); return 0; } z += p[i].a; } printf("TAK\n"); REP(i,n) { if (i) printf(" "); printf("%d", p[i].i); } printf("\n"); } |