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
#include<iostream>
#include<vector>
#include<algorithm>

#define LL long long int
#define PII std::pair<unsigned int, unsigned int>
#define PLL std::pair<LL,LL>

int main(){
	std::ios_base::sync_with_stdio(false);
	
	unsigned int n;
	LL R;
	std::cin>>n>>R;
	std::vector<PII> front;
	std::vector<PII> back;
	front.reserve(n),back.reserve(n);
	std::vector<PLL> potwory(n);
	
	for(unsigned int i=0;i<n;++i){
		std::cin>>potwory[i].first>>potwory[i].second;
		if(potwory[i].second>=potwory[i].first)
			front.push_back(PII(potwory[i].first,i));
		else
			back.push_back(PII(potwory[i].second,i));
	}
	
	std::sort(front.begin(),front.end());
	std::sort(back.begin(),back.end(),std::greater<PII>());
	front.insert(front.end(),back.begin(),back.end());
	
	bool sol=true;
	for(unsigned int i=0;i<front.size()&&(sol=(R>potwory[front[i].second].first));++i)
		R+=potwory[front[i].second].second-potwory[front[i].second].first;
	
	if(sol){
		std::cout<<"TAK"<<"\n";
		for(unsigned int i=0;i<n;++i)
			std::cout<<(front[i].second+1)<<" ";
	}
	else
		std::cout<<"NIE";
		
	std::cout<<"\n";
	
	return 0;
}