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
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string.h>
#include <stdlib.h>
#include <list>
#include <set>
#include <math.h>
#include <algorithm>
#define FOR(x,y,z) for(int x = (y); x < (z); x++)
#define FORD(x,y,z) for(int x = (y); x >= z; x--)
#define REP(r,n) for(int r = 0; r < ((int) n); r++)
#define MP make_pair
#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MAXUS 81
#define MODUL 1000
#define MAXUS2 9000005
#define INF 0xFFFFFFFU
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<int, int> PR;
typedef unsigned long long ULL;

struct monster{
	int hp, potion, position;
	monster(int hp,int pot, int pos): hp(hp), potion(pot), position(pos) {}
	bool operator<(const monster & mon) const {
		return this->hp < mon.hp || (this->hp == mon.hp && this->potion < mon.potion);
	}
};
vector< monster > monster1,monster2;
int main() {
	int z,hp,a,b;
	scanf("%d %d",&z,&hp);
	REP(i,z) {
		scanf("%d %d",&a,&b);
		if( b >= a ) monster1.emplace_back(a,b,i+1); else monster2.emplace_back(a,b,i+1);
	}
	sort(monster1.begin(),monster1.end());
	bool result = true;
	REP(i,monster1.size()) {
		if( hp < monster1[i].hp ) { result = false; break;}
		hp += monster1[i].potion - monster1[i].hp;
	}
	sort(monster2.begin(),monster2.end());
	
	if(result) {
		FORD(i,monster2.size()-1,0) {
			if( hp < monster2[i].hp ) { result = false; break;}
			hp += monster2[i].potion - monster2[i].hp;
		}
	}
	if(!result) printf("NIE\n");
	else {
		printf("TAK\n");
		REP(i,monster1.size()) printf("%d ",monster1[i].position);
		FORD(i,monster2.size()-1,0) printf("%d ",monster2[i].position);
		printf("\n");
	}
	monster1.clear();monster2.clear();

	return 0;
}