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

using namespace std;

struct monster
{
	int dmg;
	int heal;
	int id;

	monster(int a, int b, int lel)
	{
		this-> dmg = a;
		this -> heal = b;
		this -> id = lel;
	}
};

std::vector < monster > top;
std::vector < monster > bot;

bool compareDMG(monster a, monster b)
{
	return a.dmg < b.dmg;
}
bool compareHEAL(monster a, monster b)
{
	return a.heal > b.heal;
}

bool check(int hp)
{
	for(int i = 0; i < top.size(); ++i)
	{
		if (hp <= 0)
			return false;
		hp-=top[i].dmg;
		if (hp <= 0)
			return false;
		hp+=top[i].heal;
	}
	for(int i = 0; i< bot.size(); ++i)
	{
		if (hp <= 0)
			return false;
		hp -= bot[i].dmg;
		if (hp <= 0)
			return false;
		hp += bot[i].heal;
	}
	return true;
}

int main()
{
	ios_base::sync_with_stdio(false);
	int n, hp_pocz;
	cin >> n >> hp_pocz;
	for(int i = 0; i < n; ++i)
	{
		int d,h;
		cin >> d >> h;
		if(h - d > 0)
		{
			top.push_back(monster(d,h, i+1));
		}
		else
			bot.push_back(monster(d,h, i+1));
	}

	sort(top.begin(), top.end(), compareDMG);
	sort(bot.begin(), bot.end(), compareHEAL);


	if(check(hp_pocz))
	{
		cout<<"TAK"<<endl;
		for(int i = 0; i < top.size(); ++i)
		{
			cout<<top[i].id<<" ";
		}
		for(int i = 0; i< bot.size(); ++i)
		{
			cout<<bot[i].id<<" ";
		}
	}
	else cout<<"NIE"<<endl;

	return 0;
}