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

struct v {
    int a, b, c;
    inline bool operator < (const v& A) const {
        return (a < A.a);
    }
};

v makeV(const int& first, const int& second, const int& where) {
    v Test;
    Test.a = first;
    Test.b = second;
    Test.c = where;
    return Test;
}

void read(int n = 0, int m = 0) {
    scanf("%d%d", &n, &m);
    std::vector<v> Pluses, Minuses;
    int lost, achieved;
    for (int i = 0; i < n; ++i) {
        scanf("%d%d", &lost, &achieved);
        if (lost > achieved)
            Minuses.push_back(makeV(-1 * achieved, lost, i));
        else
            Pluses.push_back(makeV(lost, achieved, i));
    }
    std::sort(Pluses.begin(), Pluses.end());
    std::sort(Minuses.begin(), Minuses.end());
    int k = Minuses.size();
    for (int i = 0; i < k; ++i)
        Minuses[i].a *= -1;
    std::vector<int> Answer;
    k = Pluses.size();
    for (int i = 0; i < k; ++i)
        if (Pluses[i].a < m) {
            m += Pluses[i].b - Pluses[i].a;
            Answer.push_back(Pluses[i].c);
        }
        else {
            printf("NIE");
            goto end;
        }
    k = Minuses.size();
    for (int i = 0; i < k; ++i)
        if (Minuses[i].b < m) {
            m += Minuses[i].a - Minuses[i].b;
            Answer.push_back(Minuses[i].c);
        }
        else {
            printf("NIE");
            goto end;
        }
    printf("TAK\n");
    k = Answer.size();
    for (int i = 0; i < k; ++i)
        printf("%d ", Answer[i] + 1);
    end:
    printf("\n");
}

int main() {
    read();
    return 0;
}