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

using namespace std;

struct Monster {
	Monster(int id, int gain, int health, int poison) : Id(id), Gain(gain), Health(health), Poison(poison) {}

	int Id;
	int Gain;
	int Health;
	int Poison;

	inline bool operator<(const Monster &m) const {
		if( Gain > 0 && m.Gain > 0 )
			return Poison < m.Poison;
		else if( Gain <= 0 && m.Gain <= 0 )
			return Health > m.Health;
		else if( Gain > m.Gain )
			return true;
		return false;
	}
};

typedef vector<Monster>::iterator monsterIter;

int main()
{
	int n, z, p, h;
	long long sum;

	vector<Monster> Monsters;

	scanf("%d%d", &n, &z);

	sum = z;

	for(int i=1;i<=n;++i) {
		scanf("%d%d", &p, &h);
		sum += (h - p);
		Monsters.push_back(Monster(i, h-p, h, p));
	}

	if( sum <= 0 ) {
		puts("NIE");
	} else {
		puts("TAK");
		sort(Monsters.begin(), Monsters.end());

		for(monsterIter iter = Monsters.begin(); iter != Monsters.end(); ++iter) {
			printf("%d ", (*iter).Id);
		}
		puts("");
	}

	return 0;
}