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
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<complex>
#include<map>
#include<iomanip>
#include<sstream>
#include<queue>
#include<set>
#include<string>
#include<vector>
#include<iostream>
#include<cstring>
#include<stack>
#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 fup FOR
#define fdo FORD
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define siz SZ
#define CLR(x) memset((x), 0, sizeof(x))
#define PB push_back
#define MP make_pair
#define X first
#define Y second 
#define FI X
#define SE Y
#define SQR(a) ((a)*(a))
#define DEBUG 1
#define debug(x) {if (DEBUG)cerr <<#x <<" = " <<x <<endl; }
#define debugv(x) {if (DEBUG) {cerr <<#x <<" = "; FORE(it, (x)) cerr <<*it <<", "; cout <<endl; }}
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int>P;
typedef vector<int>VI;
const int INF=1E9+7;
template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }

struct A{long long d; long long a; int i;};
bool comp(const A& a, const A& b) {
	//najpierw te, ktore maja d<=a
		// wsrod tych - od najmniejszego d
	//potem te, ktore maja d>a
		// wsrod tych - od najwiekszego a
	bool i = a.d<=a.a;
	bool j = b.d<=b.a;
	if (i) {
		if (j) {
			return a.d<b.d;
		} else {
			return true;
		}
	} else {
		if (j) {
			return false;
		} else {
			return a.a>b.a;
		}
	}
}

A a[100007];

int main(){
	ios_base::sync_with_stdio(false);
	cout << setprecision(15) << fixed;
	long long n,z;
	cin>>n>>z;
	FOR(i,1,n) {
		cin>>a[i].d>>a[i].a;
		a[i].i=i;
	}
	sort(a+1,a+n+1,comp);
	bool fail = false;
	FOR(i,1,n) {
		z-=a[i].d;
		if (z<=0) {
			fail = true;
			break;
		}
		z+=a[i].a;
	}
	cout<<(fail?"NIE":"TAK")<<endl;
	if (!fail) {
		FOR(i,1,n)
			cout<<a[i].i<<" ";
	}
	return 0;
}