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
105
106
107
108
#include <iostream>
#include <algorithm>

using namespace std;

struct minusy {
	long long first;
	long long second;
	long long third;
};

inline minusy make_minusy(long long a, long long b, long long c) {
	minusy ret;
	ret.first = a;
	ret.second = b;
	ret.third = c;
	return ret;
}

struct comp2_ {
  inline bool operator() (const minusy &i, const minusy &j) { 
  /*if(i.first - i.second < j.first - j.second)
  		return 1;
  	else
  		return 0;*/
  		
  	if(i.first > j.first)
  		return 1;
  	else
  		return 0;
  }
} comp2;

struct comp1_ {
  inline bool operator() (const minusy &i, const minusy &j) { 
  if(i.first < j.first)
  		return 1;
  	else
  		return 0;
  }
} comp1;

long long n, z, p1, p2, plu_num, min_num;
minusy pot_min[100003], pot_plu[100003];

int main()
{
	ios_base::sync_with_stdio(0);
	
	cin>>n>>z;
	
	for(int i = 0; i < n; i++)
	{
		cin>>p1>>p2;
		
		if(p2 >= p1)
		{
			pot_plu[plu_num] = make_minusy(p1, p2, i);
			plu_num++;
		}
		else
		{
			pot_min[min_num] = make_minusy(p1, p2, i);
			min_num++;
		}
	}
	
	sort(pot_min, pot_min + min_num, comp2);
	sort(pot_plu, pot_plu + plu_num, comp1);
	
	for(int i = 0; i < plu_num; i++)
	{
		if(pot_plu[i].first >= z)
		{
			cout<<"NIE";
			return 0;
		}
		
		z = z - pot_plu[i].first + pot_plu[i].second;
	}
	//cout<<z<<"\n";
	for(int i = 0; i < min_num; i++)
	{
		//cout<<pot_min[i].first<<"\n";
		if(pot_min[i].first >= z)
		{
			cout<<"NIE";
			return 0;
		}
		
		z = z - pot_min[i].first + pot_min[i].second;
	}
	
	
	
	cout<<"TAK\n";
	/*
	for(int i = 0; i < min_num; i++)
		cout<<pot_min[i].first<<" "<<pot_min[i].second<<" "<<pot_min[i].third<<"\n";
	*/
	for(int i = 0; i < plu_num; i++)
		cout<<pot_plu[i].third + 1<<" ";
		
	for(int i = 0; i < min_num; i++)
		cout<<pot_min[i].third + 1<<" ";
	
	return 0;	
}