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

using namespace std;

inline int signum(int x)
{
	if(x >= 0) return 1;
	return -1;
}

struct monster
{
	int damage, regen;
	monster() {}
	monster(int damage, int regen) : damage(damage), regen(regen) {}
};

bool operator<(const monster &a, const monster &b)
{
	if(signum(a.regen - a.damage) != signum(b.regen - b.damage))
		return signum(a.regen - a.damage) > signum(b.regen - b.damage);
	if(a.regen - a.damage >= 0)
		return a.damage < b.damage;
	return a.regen > b.regen;
}

const int MAXN = 100 * 1000 + 5;
monster input[MAXN];
int n;
vector<int> perm;
long long hp;

bool comp(int a, int b)
{
	return input[a] < input[b];
}

bool checkPerm()
{
	for(int i : perm)
	{
		monster m = input[i];
		if(m.damage >= hp)
			return false;
		hp += m.regen - m.damage;
	}
	return true;
}

void read()
{
	scanf("%d%lld", &n, &hp);
	for(int i = 1;i<=n;i++)
		scanf("%d%d", &input[i].damage, &input[i].regen);
}

void solve()
{
	for(int i = 1;i<=n;i++)
		perm.push_back(i);
	sort(perm.begin(), perm.end(), comp);
	if(!checkPerm())
	{
		printf("NIE\n");
		return;
	}
	printf("TAK\n");
	for(int i : perm)
		printf("%d ", i);
	printf("\n");
}

int main()
{
	read();
	solve();
	return 0;
}