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
// Lupus Nocawy 14 V 2014, PA2014
// http://potyczki.mimuw.edu.pl/
// Runda 2
// Zadanie: BOH
// Bohater [B]

#include <cstdio>
#include <iostream>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define REP(i,n) for(int i=0, _n=n; i<_n; ++i)
#define FOR(i,a,b) for(int i=(a), _b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a), _b=(b); i>=_b; --i)
#define IT(i,x) __typeof__(x) i=x
#define FOREACH(it,x) for(__typeof__((x).begin()) it=(x).begin(); it!=(x).end(); ++it)
#define ALL(x) x.begin(),x.end()
#define MP make_pair
#define PB push_back
#define DEBUG(x) if(debug) cout << x << endl;
typedef long long int lli;
typedef unsigned long long int llu;
typedef pair<int,int> pii;
const int debug=0;

const int INF = 2147483647;
const int max_n = 100000;
const int max_z = 100000;

class monster{
public:
	int i,d,a;
	monster(int i, int d, int a): i(i), d(d), a(a) {}
};

bool d_less(const monster &x, const monster &y){
	return x.d < y.d;
}

bool a_greater(const monster &x, const monster &y){
	return x.a > y.a;
}

int main(void){
	int n;
	lli z;
	vector<monster> profitable;
	vector<monster> unprofitable;
	scanf("%d %lld ", &n, &z);
	REP(i,n){
		int d,a;
		scanf("%d %d ", &d, &a);
		if(d<=a)
			profitable.PB(monster(i+1,d,a));
		else
			unprofitable.PB(monster(i+1,d,a));
	}
	sort(ALL(profitable), d_less);
	sort(ALL(unprofitable), a_greater);
	FOREACH(m,profitable){
		z -= m->d;
		if(z<=0){printf("NIE\n"); return 0;}
		z += m->a;
	}
	FOREACH(m,unprofitable){
		z -= m->d;
		if(z<=0){printf("NIE\n"); return 0;}
		z += m->a;
	}
	printf("TAK\n");
	FOREACH(m,profitable){ printf("%d ", m->i); }
	FOREACH(m,unprofitable){ printf("%d ", m->i); }
	printf("\n");
	return 0;
}