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
69
70
71
72
73
74
75
76
77
78
79
//Krzysztof Kleiner
#include<iostream>
#include<cstdio>
#include<algorithm>
#define FOR(i, b, n) for ( int (i) = b; (i) < (n); (i)++)
#define FORR(i, b, n) for ( (i) = b; (i) < (n); (i)++)
#define REP(i, n) for ( int (i) = 0; (i) < (n); (i)++)
#define SC(n) scanf("%d", &(n))
#define SC2(n, m) scanf("%d%d", &(n), &(m))
#define SCLL(n) scanf("%lld", &(n))
#define PRT(n) printf("%d ", (n))
#define PRTLL(n) printf("%lld ", (n))
#define NXL printf("\n")
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<cstring>
const int MANY = 100010;

struct str
{
    int ind, mon, el;
};

str a[MANY];

int main()
{
    int n;
    LL z;
    SC(n);
    SCLL(z);
    LL sum = 0;
    REP(i, n)
    {
        a[i].ind = i;
        SC2(a[i].mon, a[i].el);
    }

    sort(a, a+n, [](str x, str y)
         {
            int xsum = x.el - x.mon;
            int ysum = y.el - y.mon;
            if(xsum > 0 && ysum <= 0)
                return true;
            if(ysum > 0 && xsum <= 0)
                return false;
            if(xsum > 0 && ysum > 0)
                return x.mon < y.mon;

            return x.el > y.el;

         });

    bool ok = 1;
    REP(i, n)
    {
        z -= a[i].mon;
        if(z <= 0)
        {
            ok = 0;
            printf("NIE\n");
            break;
        }
        z += a[i].el;
    }

    if(ok)
    {
        printf("TAK\n");
        REP(i, n)
            PRT(a[i].ind + 1);
        NXL;
    }
}