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

using namespace std;

struct Monster
{
    int i, d, a;
    bool good;
};

bool operator <(const Monster& m1, const Monster& m2)
{
    if (m1.good != m2.good) return m1.good;
    else if (m1.good) return m1.d < m2.d;
    else return m1.a > m2.a;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n, d, a, i, s;
    long long z;
    Monster p[100000];

    cin >> n >> z;
    for (i = 0; i < n; ++i)
    {
        cin >> d >> a;

        s = d - a;
        p[i].i = i;
        p[i].d = d;
        p[i].a = a;
        p[i].good = a - d >= 0;
    }
    sort(p, p + n);
    for (i = 0; i < n; ++i)
    {
        z -= p[i].d;
        if (z <= 0) break;
        z += p[i].a;
    }

    if (z > 0)
    {
        cout << "TAK" << '\n';

        cout << p[0].i + 1;
        for (i = 1; i < n; ++i)
        {
            cout << ' ' << p[i].i + 1;
        }
        cout << '\n';
    }
    else
    {
        cout << "NIE" << '\n';
    }
}