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
//Zadanie Bohater - Potyczki Algorytmiczne 2014 Runda 2B
//Aleksander Szulc 13.05.2014
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define PB push_back

const int MAXN = 100005;

struct MONSTER
{
	int dmg, hp, num;
};

int n, health;
vector<struct MONSTER> Plus, Minus;

bool CmpPlus(const MONSTER &a, const MONSTER &b)
{ return a.dmg < b.dmg; }

bool CmpMinus(const MONSTER &a, const MONSTER &b)
{
	if(a.hp > b.hp) return true;
	else if(a.hp < b.hp) return false;
	else return a.dmg > b.dmg;
}


int main()
{
	scanf("%d%d", &n, &health);
	
	for(int i=0; i<n; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		MONSTER tmp;
		tmp.dmg = a; tmp.hp = b; tmp.num = i+1;
		if(a<=b) Plus.PB(tmp);
		else Minus.PB(tmp);
	}
	sort(Plus.begin(), Plus.end(), CmpPlus);
	sort(Minus.begin(), Minus.end(), CmpMinus);
	
	for(vector<struct MONSTER>::iterator it = Plus.begin(); it!=Plus.end(); it++)
	{
		health -= it->dmg;
		if(health <= 0){ printf("NIE\n"); return 0; }
		health += it->hp;
	}
	
	for(vector<struct MONSTER>::iterator it = Minus.begin(); it!=Minus.end(); it++)
	{
		health -= it->dmg;
		if(health <= 0){ printf("NIE\n"); return 0; }
		health += it->hp;
	}
	
	printf("TAK\n");
	for(vector<struct MONSTER>::iterator it = Plus.begin(); it!=Plus.end(); it++)
		printf("%d ", it->num);
	for(vector<struct MONSTER>::iterator it = Minus.begin(); it!=Minus.end(); it++)
		printf("%d ", it->num);
	printf("\n");
	
	return 0;
}