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
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<list>
#include<math.h>
#include<algorithm>
#include<string>
#include<set>
#include<queue>
#define limit 1048576
#define inf 9223372036854775807ll
#define iinf 2147483647
#define mp make_pair
#define pb push_back
#define rep(i,k,n) for(int i=k;i<n;i++)
using namespace std;
vector<pair<pair<int,int>,int> > dmg;
vector<pair<pair<int,int>,int> > heal;
vector<int> ans;
int main(){
    int temp1,temp2;
    long long n,z;
    bool ok=true;
    scanf("%lld%lld",&n,&z);
    rep(i,1,n+1){
        scanf("%d%d",&temp1,&temp2);
        if(temp1>temp2) dmg.pb(mp(mp(temp2,temp1),i));
        else heal.pb(mp(mp(temp1,temp2),i));
    }
    sort(dmg.rbegin(),dmg.rend());
    sort(heal.begin(),heal.end());
    rep(i,0,heal.size()){
        ans.pb(heal[i].second);
        z-=heal[i].first.first;
        if(z<=0) ok=false;
        z+=heal[i].first.second;
    }
    rep(i,0,dmg.size()){
        ans.pb(dmg[i].second);
        z-=dmg[i].first.second;
        if(z<=0) ok=false;
        z+=dmg[i].first.first;
    }
    if(ok){
        printf("TAK\n");
        rep(i,0,ans.size()) printf("%d ",ans[i]);
    }
    else printf("NIE");
    return 0;
}