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

using namespace std;

struct m { int d, h, id; };

int type(m x) {
	int r = x.h - x.d;
	if (r > 0) {
		return 1;
	} else if (r == 0) {
		return 0;
	} else {
		return -1;
	}
}

bool operator< (m a, m b) {
	int ta = type(a);
	int tb = type(b);
	if (ta == tb) {
		if (ta == 1) {
			if (a.d == b.d) {
				return a.h > b.h;
			} else {
				return a.d < b.d;
			}
		} else if (ta == -1) {
			if (a.h == b.h) {
				return a.d > b.d;
			} else {
				return a.h > b.h;
			}
		} else {
			return false;
		}
	} else {
		return ta > tb;
	}
}

m a[100000];

int main() {
	ios_base::sync_with_stdio(0);
	int n, z;
	cin >> n >> z;
	for (int i = 0; i < n; i++) {
		cin >> a[i].d >> a[i].h;
		a[i].id = i+1;
	}

	sort(a, a+n);

	long long int s = z;
	bool sts = true;
	for (int i = 0; i < n; i++) {
		s -= a[i].d;
		if (s <= 0) {
			sts = false;
			break;
		}
		s += a[i].h;
	}

	if (sts) {
		cout << "TAK\n";
		for (int i = 0; i < n; i++) {
			cout << a[i].id << ' ';
		}
		cout << endl;
	} else {
		cout << "NIE\n";
	}
	return 0;
}