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

using namespace std;

struct Mon
{
	int dmg, id, hp;
	Mon(int a, int b, int c) : dmg(b), id(a), hp(c) { }
};

bool sortfunhp(Mon a, Mon b)
{
	return(a.hp > b.hp);
}

bool sortfundmg(Mon a, Mon b)
{
	return(a.dmg < b.dmg);
}


int main()
{
	ios_base::sync_with_stdio(0);
	
	int n, hps, a, b;
	cin >> n >> hps;
	
	int hp = hps;
	
	vector<Mon> stw;
	
	for(int i=1; i<=n; ++i)
	{
		cin >> a >> b;
		stw.push_back(Mon(i, a, b));
	}
	
	sort(stw.begin(), stw.end(), sortfunhp);
	
	for(int i=0; i<n; ++i)
	{
		hp-=stw[i].dmg;
		if(hp<=0)
		{
			sort(stw.begin(), stw.end(), sortfundmg);
			hp = hps;
			for(int j=0; j<n; ++j)
			{
				hp-=stw[j].dmg;
				if(hp<=0)
				{
					cout << "NIE";
					return 0;
				}
				hp+=stw[j].hp;
			}
		}
		hp+=stw[i].hp;
	}	
	
	cout << "TAK\n";
	for(int i=0; i<n; ++i)
	{
		cout << stw[i].id << " ";
	}
	
	return 0;
}