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
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <list>
#include <climits>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>

#define ALL(v) v.begin(), v.end()
#define REP(i, a, b) for(unsigned int i = a; i < b; i++)
#define REPD(i, a, b) for(unsigned int i = a; i > b; i--)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORD(i, a, b) for(int i = a; i >= b; i--)
#define LOG(i) cout << "heh" << i << endl;
#define INF 1000000001

#define PB push_back
#define MP make_pair
#define PI pair<int, int>
#define st first
#define nd second

using namespace std;

int n;
int D[1000001];
int A[1000001];
vector<int> P, M, R;
int c;

struct Less
{
    inline bool operator() (const int a, const int b)
    {
        return (D[a] < D[b]);
    }
};

struct More
{
    inline bool operator() (const int a, const int b)
    {
        return (D[a] > D[b]);
    }
};

int main()
{
	ios_base::sync_with_stdio(0);
	cin >> n >> c;
	REP(i, 0, n) {
        cin >> D[i] >> A[i];
        if(A[i] >= D[i]) P.PB(i);
        else M.PB(i);
	}
    sort(ALL(P), Less());
    sort(ALL(M), More());

    bool ok = true;

    REP(i, 0, P.size()) {
        if(c < D[P[i]]) {
            ok = false; break;
        }
        c -= D[P[i]]; c += A[P[i]];
        R.PB(P[i]);
    }

    REP(i, 0, M.size()) {
        if(c < D[M[i]]) {
            ok = false; break;
        }
        c -= D[M[i]]; c += A[M[i]];
        R.PB(M[i]);
    }

    if(!ok) cout << "NIE" << endl;
    else {
        cout << "TAK" << endl;
        REP(i, 0, R.size()) cout << R[i] + 1<< " ";
        cout << endl;
    }

    return 0;
}