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
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <stdio.h>
#include <algorithm>

typedef long long int int64;

struct Mob
{
	int order;
	int damage;
	int heal;
	int diff;
};

Mob* monstersPlus;
Mob* monstersMinus;

bool mySortPlus(const Mob& a, const Mob& b)
{
	if (a.damage < b.damage)
		return true;
	if (a.damage == b.damage)
		return a.heal > b.heal;
	return false;
}

/*bool mySortMinus(const Mob& a, const Mob& b)
{
	if (a.damage > b.damage)
		return true;
	if (a.damage == b.damage)
		return a.heal > b.heal;
	return false;
}*/

bool mySortMinus(const Mob& a, const Mob& b)
{
	if (a.heal > b.heal)
		return true;
	if (a.heal == b.heal)
		return a.damage < b.damage;
	return false;
}


int main()
{
	int n, z;
	int d, a;
	int numMonsPlus;
	int numMonsMinus;
	scanf("%d %d", &n, &z);
	
	monstersPlus = new Mob[n];
	monstersMinus = new Mob[n];
	numMonsPlus = 0;
	numMonsMinus = 0;

	for (int i = 0; i < n; ++i)
	{
		scanf("%d %d", &d, &a);
		if (a - d >= 0)
		{
			monstersPlus[numMonsPlus].order = i + 1;
			monstersPlus[numMonsPlus].damage = d;
			monstersPlus[numMonsPlus].heal = a;
			monstersPlus[numMonsPlus].diff = a - d;
			numMonsPlus++;
		}
		else
		{
			monstersMinus[numMonsMinus].order = i + 1;
			monstersMinus[numMonsMinus].damage = d;
			monstersMinus[numMonsMinus].heal = a;
			monstersMinus[numMonsMinus].diff = a - d;
			numMonsMinus++;
		}
	}

	std::sort(monstersPlus, monstersPlus + numMonsPlus, mySortPlus);
	std::sort(monstersMinus, monstersMinus + numMonsMinus, mySortMinus);

/*	for (int i = 0; i < numMonsPlus; ++i)
	{
		printf("%d. %d %d = %d\n",monstersPlus[i].order, monstersPlus[i].damage, monstersPlus[i].heal, monstersPlus[i].diff);
	}
	for (int i = 0; i < numMonsMinus; ++i)
	{
		printf("%d. %d %d = %d\n", monstersMinus[i].order, monstersMinus[i].damage, monstersMinus[i].heal, monstersMinus[i].diff);
	}*/

	int64 health = (int64)z;
	for (int i = 0; i < numMonsPlus; ++i)
	{
		health -= monstersPlus[i].damage;
		if (health <= 0)
		{
			printf("NIE\n");
			delete[] monstersPlus;
			delete[] monstersMinus;
			return 0;
		}
		health += monstersPlus[i].heal;
	}

	for (int i = 0; i < numMonsMinus; ++i)
	{
		health -= monstersMinus[i].damage;
		if (health <= 0)
		{
			printf("NIE\n");
			delete[] monstersPlus;
			delete[] monstersMinus;
			return 0;
		}
		health += monstersMinus[i].heal;
	}

	printf("TAK\n");
	for (int i = 0; i < numMonsPlus; ++i)
		printf("%d ", monstersPlus[i].order);
	for (int i = 0; i < numMonsMinus; ++i)
		printf("%d ", monstersMinus[i].order);
	printf("\n");

	delete[] monstersPlus;
	delete[] monstersMinus;
	return 0;
}