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
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


struct comp_a_ {
  bool operator() (pair<pair<int,int>,int> i, pair<pair<int,int>,int> j) {
  	return (i.first.first<j.first.first);
  }
} comp_a;

struct comp_b_ {
  bool operator() (pair<pair<int,int>,int> i, pair<pair<int,int>,int> j) {
  	return (i.first.second>j.first.second);
  }
} comp_b;


int main(void) {
	ios_base::sync_with_stdio(0);	
	int n, hp, buf0, buf1;
	cin>>n>>hp;
	vector< pair< pair<int,int>, int> > A, B;
	
	for(int it=0;it<n;++it) {
		cin>>buf0>>buf1;
		if(buf1-buf0>0) {
			A.push_back(make_pair(make_pair(buf0, buf1), it+1));
		} else {
			B.push_back(make_pair(make_pair(buf0, buf1), it+1));
		}	
	}
	sort(A.begin(), A.end(), comp_a);
	sort(B.begin(), B.end(), comp_b);
	const int lena = A.size();
	const int lenb = B.size();
	bool good = true;
	
	vector<int> res;
	for(int it=0;it<lena;++it) {
		if(A[it].first.first>=hp) {
			good=false;
			break;	
		}
		hp+=-A[it].first.first+A[it].first.second;
		res.push_back(A[it].second);
	}
	if(good) {
		for(int it=0;it<lenb;++it) {
			if(B[it].first.first>=hp) {
				good=false;
				break;
			}
			hp+=-B[it].first.first+B[it].first.second;
			res.push_back(B[it].second);
		}	
	}
		
	if(good) {
		cout<<"TAK\n";	
		for(int it=0;it<n;++it) {
			cout<<res[it]<<" ";	
		}
		cout<<"\n";
	} else {
		cout<<"NIE\n";	
	}
	
	return 0;
}