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 <stdio.h>
#include <set>
#include <queue>
#include <stdint.h>

using namespace std;

inline int get_int()
{
	int ret = 0;
	int c = getchar_unlocked();
	while(c<'0' || c>'9') c = getchar_unlocked();
	while(c>='0' && c<='9')
	{
		ret = (ret<<3) + (ret<<1) + (c-'0');
		c = getchar_unlocked();
	}
	return ret;
}

typedef pair<int, int> ii;
typedef pair<ii, int> item;

struct Monster
{
	int d;
	int a;
	int r;
};

Monster monsters[100000+1];

bool fight(priority_queue<pair<int, int> > & Q, int64_t & Z, queue<int> & R)
{
	while(!Q.empty() && Z > 0)
	{
		int i = Q.top().second;
		
		if(Z > (int64_t)monsters[i].d)
		{
			Z += (int64_t)monsters[i].r;

			Q.pop();

			if(Z > 0)
			{
				R.push(i);
			}
		}
		else
		{
			return false;
		}
	}

	return true;
}

int main()
{
	int N = get_int();
	int64_t Z = (int64_t)get_int();
	priority_queue<pair<int, int> > Qp;
	priority_queue<pair<int, int> > Qm;
	for(int i = 1; i <= N; i++)
	{
		monsters[i].d = get_int();
		monsters[i].a = get_int();
		monsters[i].r = monsters[i].a - monsters[i].d;
		if(monsters[i].r > 0)
		{
			Qp.push(pair<int, int>(-monsters[i].d, i));
		}
		else
		{
			Qm.push(pair<int, int>(monsters[i].d, i));
		}
	}
	queue<int> R;
	
	bool ret = fight(Qp, Z, R);

	if(ret)
	{
		fight(Qm, Z, R);
	}

	if(Z > 0 && R.size() == N)
	{
		printf("TAK\n");
		while(!R.empty())
		{
			printf("%d ", R.front());
			R.pop();
		}
		printf("\n");
	}
	else
	{
		printf("NIE\n");
	}
}