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
91
#include <cstdio>
#include <algorithm>
using namespace std;
//#define LOG(args...) 
#define LOG(args...) fprintf(stderr, args)
#define FOR(i, n) for(int i = 0, __n = (n); i<__n; i++)





struct potw : public pair<int,int> {
	int pos;
	bool operator<(const potw & x) const {
		if(first <= second) { 
			if(x.first > x.second) return 1;
			return first < x.first;
		} else {
			if(x.first <= x.second) return 0;
			return second > x.second;
		}	
	}
	potw(){}
	potw(int a, int b, int pos): pair<int,int>(a,b), pos(pos){}
} t[100000], qa[100000], qd[100000];

struct ctrfirst {
	int operator()(const potw & a) const {
		return a.first;
	}
};

struct ctrsecond {
	int operator()(const potw & a) const {
		return a.second;
	}
};

template<class T, class fn>
void countSort(T* from, T* to, int n, int maxhash, fn hash) {

	int* ctr = new int[maxhash];
	FOR(i, maxhash) ctr[i] = 0;
	FOR(i, n) {
		ctr[hash(from[i])]++;
	}
	int prev = 0;
	FOR(i, maxhash) {
		int next = prev;
		prev += ctr[i];
		ctr[i] = next;
	}
	FOR(i, n) {
		int idx = ctr[hash(from[i])]++;
		to[idx] = from[i];
	}
	delete [] ctr;
}


int main() {
	int n, h; scanf("%d%d", &n, &h);
	int na = 0, nd = 0;
	FOR(i, n) {
		int a,b; scanf("%d%d", &a, &b);
		if(a <= b) {
			qa[na++] = potw(a,b, i+1	);
		} else {
			qd[nd++] = potw(a,b, i+1	);
		}
	}
	
	countSort(qa, t, na, 100010, ctrfirst());
	countSort(qd, t+na, nd, 100010, ctrsecond());
	reverse(t+na, t+n);
	
	bool res = true;
	FOR(i,n) {
		h-=t[i].first;
		if(h<=0) {
			res = false;
			break;
		}
		h+=t[i].second;
	}
	if(res) {
		printf("TAK\n");
		FOR(i,n) printf("%d ", t[i].pos);
		printf("\n");
	} else printf("NIE\n");
}