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
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main () {
    int n, z, a, b, t;
    cin >> n >> z;
    vector < pair <int, int> > pot;
    vector < pair <int, int> > obj;
    
    for (int i = 0; i < n; i ++){
    	   cin >> a >> b;
    	   obj.push_back(make_pair(b - a, i));
    	   pot.push_back(make_pair(a, b));
    }
    
    sort(obj.begin(), obj.end());
    
    for (int i = 0; i < obj.size(); i ++){
    	   if ((z - pot[obj[i].second].first) <= 0){
    	       cout << "NIE" << endl;
            return 0;
    	   }
    	   z += obj[obj.size() - i - 1].first;
    }
    
    if (z > 0){
    	  cout << "TAK" << endl;
    	  for (int i = 0; i < obj.size(); i ++){
    	  	 cout << obj[obj.size() - i - 1].second + 1 << " ";
    	  }
    	  cout << endl;
    } else {
    	  cout << "NIE" << endl;
    }
    
    return 0;
}