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

long long a[100000];
long long d[100000];
int w[100000];
pair<long long,int> A[4000000];
pair<long long,int> B[4000000];

int main(){
	int As = 0;
	int Bs = 0;
	long long n,z;
	cin>>n>>z;
	for(int i = 0; i < n;i++)
		cin>>d[i]>>a[i];
	for(int i =0;i<n;i++)
		if(d[i]<=a[i]){
			A[As].first = d[i];
			A[As].second = i;
			As++;
		}else{
			B[Bs].first = -a[i];
			B[Bs].second = i;
			Bs++;
		}
	sort(A,A+As);
	sort(B,B+Bs);
	int j =0;
	bool ok = true;
	for(int i =0;i<As;i++){
		z-=d[A[i].second];
		if(z<=0){ok = false;break;}
		z+=a[A[i].second];
		w[j]=A[i].second;
		j++;
	}
	for(int i =0;i<Bs;i++){
		z-=d[B[i].second];
		if(z<=0){ok = false;break;}
		z+=a[B[i].second];
		w[j]=B[i].second;
		j++;
	}
	if(ok){
		cout<<"TAK\n";
		for(int i =0;i<n;i++)
			cout<<w[i]+1<<" ";
	}else{
		cout<<"NIE\n";
	}
	return 0;
}