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 <vector>
#include <algorithm>

class Dragon{
public:
    int id, d, a;
    Dragon(int id, int d, int a): id(id), d(d), a(a) {}
};

bool less(const Dragon &x, const Dragon &y) {
    return - x.d + std::min(x.a - y.d, 0) > - y.d + std::min(y.a - x.d, 0);
}

int main() {
    int n, z, d, a;
    std::vector<Dragon> dragons;

    scanf("%d", &n);
    scanf("%d", &z);

    dragons.reserve(n);

    for (int i = 0; i < n; ++i) {
        scanf("%d", &d);
        scanf("%d", &a);
        dragons.push_back(Dragon(i, d, a));
    }

    std::sort(dragons.begin(), dragons.end(), less);

    /*
    for(std::vector<Dragon>::iterator i = dragons.begin(); i != dragons.end(); ++i) {
        fprintf(stderr, "%d %d %d\n", i->id, i->d, i->a);
    }
    */


    for(std::vector<Dragon>::iterator it = dragons.begin(); it != dragons.end(); ++it) {
        if (z <= 0) {
            break;
        }
        z -= it->d;
        if (z <= 0) {
            break;
        }
        z += it->a;
    }

    if (z > 0) {
        printf("TAK\n");
        bool notfirst = false;
        for(std::vector<Dragon>::iterator it = dragons.begin(); it != dragons.end(); ++it) {
            if (notfirst) {
                printf(" ");
            } else {
                notfirst = true;
            }
            printf("%d", it->id + 1);
        }
        printf("\n");
    } else {
        printf("NIE\n");
    }


}