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
#include <cstdio>
#include <algorithm>

using namespace std;

#define FOR(v,p,k) for(int v=p;v<=k;++v)
#define FORD(v,p,k) for(int v=p;v>=k;--v)
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(x) memset(x,0,sizeof(x))

typedef long long LL;
typedef unsigned long long ULL;

const int INF = 1000000000;

const int MAX = 100000;
int D[MAX], A[MAX];
int G[MAX], B[MAX];
int R[MAX];

bool compG(int x, int y) 
{ 
	return D[x] < D[y] || (D[x] == D[y] && A[x] > A[y]) || (D[x] == D[y] && A[x] == A[y] && x < y);
}

bool compB(int x, int y) 
{ 
	return A[x] < A[y] || (A[x] == A[y] && D[x] > D[y]) || (A[x] == A[y] && D[x] == D[y] && x < y);
}

int main(int argc, char **args)
{
	int n, d, a;
	LL z;

	scanf("%d %lld", &n, &z);

	int gCnt = 0, bCnt = 0, rCnt = 0;
	LL ze = z;

	REP(i, n)
	{
		scanf("%d %d", &d, &a);

		D[i] = d;
		A[i] = a;

		ze += a - d;

		if (a >= d)
			G[gCnt++] = i;
		else
			B[bCnt++] = i;
	}

	sort(G, G + gCnt, compG);
	sort(B, B + bCnt, compB);

	bool found = true;

	REP(i, gCnt)
	{
		if (z <= D[G[i]])
		{
			found = false;
			break;
		}

		z += A[G[i]] - D[G[i]];
		R[rCnt++] = G[i] + 1;
	}

	if (found)
	{
		rCnt = n - 1;

		REP(i, bCnt)
		{
			if (ze <= A[B[i]])
			{
				found = false;
				break;
			}

			ze += D[B[i]] - A[B[i]];
			R[rCnt--] = B[i] + 1;
		}
	}

	if (found)
	{
		printf("TAK\n");
		REP(i, n - 1)
			printf("%d ", R[i]);
		printf("%d\n", R[n - 1]);
	}
	else
		printf("NIE\n");

	return 0;
}