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
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

struct vert{
	int a;
	int b;
	int nbr;
};

bool oper1(vert pe1, vert pe2){
	return (pe1.a<pe2.a);
}
bool oper2(vert pe1, vert pe2){
	return (pe1.b>pe2.b);
}
int main(){
	int n;
	
	int a; int b;
	long long int init=0; bool ok = true;
	scanf("%d %d",&n,&init);
	vert* P=new vert[n];int sp=0;
	vert* Q=new vert[n];int sq=0;
	for(int i=0;i<n;i++){
		scanf("%d %d",&a,&b);
		if(b>=a){
			P[sp].nbr=i+1;
			P[sp].a=a;
			P[sp].b=b;sp++;
		}else{
			Q[sq].nbr=i+1;
			Q[sq].a=a;
			Q[sq].b=b;sq++;
		}
	}
	
	sort(P,P+sp,oper1);
	
	for(int i=0;i<sp;i++){
		init = init - P[i].a;
		if(init<=0){ok=false;break;}
		init = init + P[i].b;
		
		
	}
	sort(Q,Q+sq,oper2);
	for(int i=0;i<sq;i++){
		init=init-Q[i].a;
		if(init<=0){ok=false;break;}
		init=init+Q[i].b;
	}
	if(ok==true){
		printf("TAK\n");
		for(int i=0;i<sp;i++)printf("%d ",P[i].nbr);
		for(int i=0;i<sq;i++)printf("%d ",Q[i].nbr);
		printf("\n");
	}else{
		printf("NIE\n");
	}
	return 0;
}