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
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int i, n, ob, moc, j = 0;
long long z;
vector < pair<int,  pair<int,int> >  > DOD, UJ; // obrazenia, moc, numer, moc, obrazenia, numer  
int W[100001];

int main() {
	scanf("%d%lld",&n,&z);
	for(i = 1; i <= n; ++i) {
		scanf("%d%d",&ob,&moc);
		if (moc - ob > 0) DOD.push_back(make_pair(ob, make_pair(moc, i)) );
		else UJ.push_back(make_pair(moc, make_pair(ob, i)) );
	}
	sort(DOD.begin(), DOD.end());
	sort(UJ.rbegin(), UJ.rend());
	for(i = 0; i < DOD.size(); ++i) {
		if (DOD[i].first < z)  {
			z = z + (DOD[i].second.first - DOD[i].first);
			W[j++] = DOD[i].second.second;
		}
		else {
			printf("NIE\n");
			return 0;
		}
	}
	for(i = 0; i < UJ.size(); ++i) {
		if (UJ[i].second.first < z)  {
			z = z + UJ[i].first - UJ[i].second.first;
			W[j++] = UJ[i].second.second;
		}
		else {
			printf("NIE\n");
			return 0;
		}
	}
	printf("TAK\n");
	for(i = 0; i < n; ++i) printf("%d ",W[i]);

return 0;
 
}