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
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
vector<pair<int,int > >pluss;
vector<pair<int,int > >minuss;
vector<int>w;
int tab[1000000];
int main(){
	int t,n,p1,p2;
	scanf("%d%d",&n,&t);
	for(int i = 0; i<n;++i){
		scanf("%d%d",&p1,&p2);
		tab[i]=p2-p1;
		if(p2-p1>=0)pluss.push_back(make_pair(p1,i));
		else minuss.push_back(make_pair(p1,i));
	}
	sort(pluss.begin(),pluss.end());
	sort(minuss.begin(),minuss.end());
	for(int i = 0; i<pluss.size();++i){
		t-=pluss[i].first;
		if(t<=0){printf("NIE");return 0;}
		t+=tab[pluss[i].second]+p1;
		w.push_back(pluss[i].second);
	}
	for(int i = minuss.size()-1; i>=0;--i){
		t-=minuss[i].first;
		if(t<=0){printf("NIE");return 0;}
		t+=tab[minuss[i].second]+p1;
		w.push_back(minuss[i].second);
	}	
	printf("TAK\n");
	for(int i = 0; i<n;++i)printf("%d ",w[i]+1);
	
	return 0;
}