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
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <cctype>
#include <cmath>
#include <iostream>
#include <set>
#include <map>
#include <sstream>
#include <typeinfo>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<string> vs;
 
#define SIZE(x) ((int)(x.size()))
#define LET(var, val) typeof(val) var = (val)
#define FOR(k, a, b) for(typeof(a) k = (a); k < (b); ++k)
#define FORR(k, a, b) for(typeof(a) k = (a); k >= (b); --k)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for(LET(i, (c).begin()); i != (c).end(); ++i)
#define PB push_back
#define PF push_front
 
const int INF = 2000000001;
const double EPS = 10e-9;
const double PI = acos(-1.0);
 
ostringstream out;

struct Monster
{
	int damage;
	int reward;
	int number;
};


bool monster_cmp(Monster a, Monster b)
{
	return (a.damage < b.damage);
}

bool monster_cmp2(Monster a, Monster b)
{
	return (a.reward > b.reward);
}


struct cmp {
  	bool operator() (const Monster& a, const Monster& b) const
  	{
  		return (a.reward - a.damage < b.reward - b.damage);
  	}
};

Monster monsters[100005];
Monster going_down[100005];
int difference[100005];
multiset<Monster, cmp> attackable;

int main()
{
	ios_base::sync_with_stdio(0);
	int n, life;
	cin >> n >> life;

	REP(i, n)
	{
		cin >> monsters[i].damage >> monsters[i].reward;
		monsters[i].number = i + 1;
	}
	monsters[n].damage = INF;
	monsters[n].reward = 0;
	monsters[n].number = n;
	sort(monsters, monsters + n, monster_cmp);
	int i = 0;
	int count = 0;
	while (monsters[i].damage < life)
			attackable.insert(monsters[i++]);
	while(SIZE(attackable) > 0)
	{
		if (attackable.rbegin()->reward < attackable.rbegin()->damage)
			break;
		out << attackable.rbegin()->number << " ";
		count++;
		life -= attackable.rbegin()->damage;
		if (life <= 0) break;
		life += attackable.rbegin()->reward;
		attackable.erase(--attackable.end());

		while (monsters[i].damage < life)
			attackable.insert(monsters[i++]);

	}
	{
		int j = 0;
		FOREACH(k, attackable)
		{
			going_down[j].reward = k->reward;
			going_down[j].number = k->number;
			going_down[j].damage = k->damage;
			j++;
		}
		sort(going_down, going_down + j, monster_cmp2);
		REP(k, j)
		{
			out << going_down[k].number << " ";
			life -= going_down[k].damage;
			if (life <= 0)
				break;
			life += going_down[k].reward;
		}
	}
	if (life > 0 && i == n) cout << "TAK\n" << out.str() << endl;
	else cout << "NIE\n";
	return 0;
}