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
#include<bits/stdc++.h>
#define ALL(X)      X.begin(),X.end()
#define FOR(I,A,B)  for(int (I) = (A); (I) <= (B); (I)++)
#define FORW(I,A,B) for(int (I) = (A); (I) < (B);  (I)++)
#define FORD(I,A,B) for(int (I) = (A); (I) >= (B); (I)--)
#define CLEAR(X)    memset(X,0,sizeof(X))
#define PB          push_back
#define MP          make_pair
#define X           first
#define Y           second
using namespace std;
typedef signed long long slong;
typedef long double ldouble;
const slong Infinity = 1000000100;
const ldouble Epsilon = 1e-9;
template<typename T, typename U> ostream& operator << (ostream& os, const pair<T,U>&p) {return os << "(" << p.X << "," << p.Y << ")"; }
template<typename T> ostream& operator << (ostream &os, const vector<T>& V) { os << "["; FORW(i,0,size(V)) os << V[i] << ((i==size(V)-1) ? "" : ","); return os << "]"; }
template<typename T> ostream& operator << (ostream &os, const set<T>& S) {os << "("; for(auto i: S) os << i << (i==*S.rbegin()?"":","); return os << ")"; }
template<typename T, typename U> ostream& operator << (ostream &os, const map<T, U>& M){os << "{"; for(auto i: M) os << i << (i.X==M.rbegin()->X?"":","); return os << "}"; }
template<typename T, typename F> T lbound(T p, T q, F f) { static_assert(is_integral<T>::value, "integral type required"); while(p < q) { T r = p+(q-p)/2; if(f(r)) q = r; else p = r+1; } return p; }
template<typename T, typename F> T lboundl(T p, T q, F f) { static_assert(is_floating_point<T>::value, "floating point type required"); FOR(i,1,70) { T r = (p+q)/2; if(f(r)) q = r; else p = r; } return p; }
template<typename T, typename U> bool contain(T t, U u) { return t.find(u) != t.end(); }
template<typename T> int size(T t) { return t.size(); }

const int MAXN = 1001000;
int N;
slong H;
slong A[MAXN];
slong B[MAXN];

void read_data()
{
	scanf("%d %lld", &N, &H); 
	FOR(i,1,N) scanf("%lld %lld", A+i, B+i);
}

vector<int> R;

bool solve()
{
	vector<pair<slong,int>> V;
	FOR(i,1,N) V.PB(MP(A[i],i));
	int t = -1;
	sort(ALL(V));
	set<pair<slong,int>> S;
	FOR(i,1,N)
	{
		while(t != N-1 and V[t+1].X < H) 
		{
			++t;
			if(B[V[t].Y] >= A[V[t].Y]) S.insert(MP(-Infinity,V[t].Y));
			else S.insert(MP(-B[V[t].Y],V[t].Y));
		}
		//cout << S << endl;
		if(S.empty()) return false;
		int id = S.begin()->Y;
		S.erase(S.begin());
		H -= A[id];
		if(H <= 0) return false;
		H += B[id];
		R.PB(id);
	}
	return true;
}

int main() 
{
	read_data();
	if(solve())
	{
		printf("TAK\n");
		for(int r: R) printf("%d ", r);
		printf("\n");
	}
	else
	{
		printf("NIE\n");
	}
	//cout << "R: " << R << endl;
	return 0;
}