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
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <iostream>
#include <algorithm>

using namespace std;

template<typename T, int MAXN >
struct ST {
	typedef function<T(const T&, const T&)> Oper;

	T tree[MAXN*2];
	int n;
	Oper oper;
	T def;

	static int find_pow(int k) {
		int r = 1;
		while(r < k) r*=2;
		return r;
	}

	ST(int _n, T _def, Oper _oper) {
		def = _def;
		oper = _oper;
		n = find_pow(_n);
		fill(tree, tree+2*n, def);
	}

	void Set(int A, const T &v) {
		int a = A + n;
		tree[a] = v;
		a /= 2;

		while(a) {
			tree[a] = oper(tree[2*a], tree[2*a+1]);

			a/=2;
		}
	}

	T Query(int A, int B) {
		int a = A + n, b = B + n;
		T r = def;

		while(a<b) {
			if(a%2 == 1)
				r = oper(tree[a], r);

			if(a%2 == 0) a = a/2;
			else a = a/2 + 1;

			if(b%2 == 1)
				r = oper(tree[b-1], r);
			b/=2;
		}

		return r;
	}

	int Val(int A) {
		return tree[A+n];
	}

/*	void Debug() {
		for(int i=1; i<=n; i*=2) {
			for(int j=0; j<i; ++j)
				printf("%*d", 2*n/i, tree[i+j]);
			printf("\n");
		}
	}

	void Interactive() {
		char c[100];
		while(scanf("%s", c)) {
			if(c[0] == 's') {
				int a, b;
				scanf("%d%d", &a, &b);
				Set(a, b);
			} else if(c[0] == 'd') {
				Debug();
			} else if(c[0] == 'q') {
				int a, b;
				scanf("%d%d", &a, &b);
				int q = Query(a,b);
				printf("%d\n", q);
			}
		}
	}	*/
};


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n, z;
	cin >> n >> z;
	vector<tuple<int, int, int> > tab(n);
	int j=0;
	for(auto &tup : tab) {
		int a, b; 
		cin >> a >> b;
		tup = make_tuple(a, b, j+1);
		++j;
	}

	sort(tab.begin(), tab.end());

	ST<tuple<int, int>, 1<<18> tree(n, make_tuple(-1, 0), 
		[](const tuple<int, int> &a, const tuple<int, int> &b) { return max(a,b); });
	for(int i=0; i<n; ++i) tree.Set(i, make_tuple(get<1>(tab[i]), i));

	bool correct = true;

	vector<int> res;

	for(int i=0; i<n && correct; ++i) {
		auto it = lower_bound(tab.begin(), tab.end(), make_tuple(z+1, -1, 0));
		if(it == tab.begin()) {
			correct = false;
			break;
		}

		int dist = distance(tab.begin(), it);
		auto cur = tree.Query(0, dist);
		int a, b;
		tie(b, a) = cur;

		if(b == -1) {
			correct = false;
			break;
		}

		tree.Set(a, make_tuple(-1, a));

		z = z - get<0>(tab[a]) + get<1>(tab[a]);

		if(z<=0) correct = false;
		res.push_back(get<2>(tab[a]));
	}

	cout << (correct? "TAK" : "NIE") << endl;

	if(correct) {
		for(auto &x : res)
			cout << x << " ";
		cout << "\n";
	}



	return 0;
}