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

using namespace std;

int main(){
	int n,z,d,a,*it;
	bool win=true;
	cin>>n>>z;
	it=new int[n];
	vector<pair<pair<int,int>,int > > da;
	for(int i=0;i<n;i++){
		cin>>d>>a;
		da.push_back(make_pair(make_pair(a,-d),i+1));
	}
	sort(da.rbegin(),da.rend());
	for(int i=0;i<n;i++){
		z+=da[i].first.second;
		if(z<=0){
			win=false;
			break;
		}
		z+=da[i].first.first;
	}	
	if(win){
		cout<<"TAK\n";
		for(int i=0;i<n;i++)
			cout<<da[i].second<<" ";
	}
	else
		cout<<"NIE";
	
	
	
	return 0;
}