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
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;


int main() {
    vector <int> res;
    long long n, z;
    cin>>n>>z;
    vector <pair<int,pii> > M;
    for(int i = 0; i < n; i++) {
	int tmp1,tmp2;
	cin>>tmp1>>tmp2;
	M.push_back(pair<int,pii>(tmp2-tmp1,pii(tmp1,tmp2)));
    }
    vector <pair<pii,int> > plus;
    vector <pair<int,pair<pii,int> > > minus;
    for(int i = 0; i < M.size(); i++) {
	if(M[i].first >= 0) plus.push_back(pair<pii,int>(pii(M[i].second.first,M[i].second.second),i));
	else minus.push_back(pair<int,pair<pii,int> >(M[i].second.first+M[i].second.second,pair<pii,int>(pii(M[i].second.first,M[i].second.second),i)));
    }
    
    sort(plus.begin(),plus.end());
    if(plus.size() > 0)
	if(z-plus[0].first.first <= 0) {
	    cout<<"NIE"<<endl;
	    return 0;
	}
    for(int i = 0; i < plus.size(); i++) {
	z -= (plus[i].first.first-plus[i].first.second);
	res.push_back(plus[i].second+1);
    }
    
    sort(minus.begin(),minus.end());
        
    for(int i = minus.size()-1; i >= 0; i--) {
	z -= (minus[i].second.first.first);
	res.push_back(minus[i].second.second+1);
	if(z <= 0) {
	    cout<<"NIE"<<endl;
	    return 0;
	}
	z += minus[i].second.first.second;
    }
    cout<<"TAK"<<endl;
    for(int i = 0; i < res.size(); i++)
	cout<<res[i]<<" ";
    cout<<endl;   
}