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
#include <cstdio>
#include <utility>
#include <set>

using namespace std;

typedef pair<int, int> PII;
typedef pair<int, PII> PIPII;

struct comp_d {
	bool operator() (const PIPII& lhs, const PIPII& rhs) const {
		int ld = lhs.second.first;
		int rd = rhs.second.first;

		if (ld != rd) {
			return ld < rd;
		}

		return lhs.first < rhs.first;
	}
};

struct comp_a {
	bool operator() (const PIPII& lhs, const PIPII& rhs) const {
		int la = lhs.second.second;
		int ra = rhs.second.second;

		if (la != ra) {
			return la > ra;
		}

		return lhs.first < rhs.first;
	}
};

typedef set<PIPII, comp_d> SD;
typedef set<PIPII, comp_a> SA;

int n, z;
long long l;
SD pp;
SA pm;
PIPII p;

int i, j, a, d;

int main() {
	scanf("%d %d", &n, &z);
	l = 1LL * z;

	for (i = 0; i < n; ++i) {
		scanf("%d %d", &d, &a);

		p = make_pair(i + 1, make_pair(d, a));
		if (d > a) {
			pm.insert(p);
		} else {
			pp.insert(p);
		}
	}

	for (SD::iterator itd = pp.begin(); itd != pp.end(); ++itd) {
		p = *itd;

		if (p.second.first >= l) {
			printf("NIE\n");
			return 0;
		}

		l += p.second.second - p.second.first;
	}

	for (SA::iterator ita = pm.begin(); ita != pm.end(); ++ita) {
		p = *ita;

		if (p.second.first >= l) {
			printf("NIE\n");
			return 0;
		}

		l += p.second.second - p.second.first;
	}

	if (l <= 0) {
		printf("NIE\n");
		return 0;
	}

	printf("TAK\n");
	for (SD::iterator itd = pp.begin(); itd != pp.end(); ++itd) {
		p = *itd;
		printf("%d ", p.first);

	}

	for (SA::iterator ita = pm.begin(); ita != pm.end(); ++ita) {
		p = *ita;
		printf("%d ", p.first);
	}
	printf("\n");
	

	return 0;
}