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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <set>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

const int INF = 1 << 30;
const double EPS = 1e-12;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    ll z;
    cin>>n>>z;
    vector<pii> dod, uj;
    vi v(n);
    for(int i=0; i<n; i++)
    {
        int d, a;
        cin>>d>>a;
        if(d<=a)
        {
            dod.pb(mp(d,i));
            v[i]=a;
        }
        else
        {
            uj.pb(mp(a,i));
            v[i]=d;
        }
    }
    sort(dod.begin(), dod.end());
    sort(uj.begin(), uj.end());
    int ok=1;
    for(int i=0; i<dod.size(); i++)
    {
        z-=ll(dod[i].fi);
        if(z<=0) ok=0;
        z+=ll(v[dod[i].se]);
    }
    for(int i=int(uj.size())-1; i>=0; i--)
    {
        z-=ll(v[uj[i].se]);
        if(z<=0) ok=0;
        z+=ll(uj[i].fi);
    }
    if(ok)
    {
        cout<<"TAK\n";
        for(int i=0; i<dod.size(); i++)
        {
            cout<<dod[i].se+1<<" ";
        }
        for(int i=int(uj.size())-1; i>=0; i--)
        {
            cout<<uj[i].se+1<<" ";
        }
    }
    else cout<<"NIE\n";
}