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
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cstring>
#include <stack>
#include <cstring>
using namespace std;

//Defines
#define FIRST(a) (a).begin()
#define REMOVE_FIRST(a) (a).erase((a).begin())
#define REMOVE_LAST(a) (a).erase(--(a).end())
#define LAST(a) (--(a).end())
#define PRINT_ALL(a) for(typeof((a).begin()) it = (a).begin(); it != (a).end(); it++ ) printf("%d ", *it);
#define ALL(t) (t).begin(),(t).end()
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define DBG(var) cerr << #var << " = " << var << endl;
#define p_int pair<int, int>
#define v_int vector<int>
#define PB push_back
#define LL long long int
#define MP make_pair
#define f first
#define s second
#define TEST(name) freopen(name, "r", stdin);
#define IOS ios_base::sync_with_stdio(0)
#define print(n){cout<<n<<endl;}
#define mod 1000000009
#define INF 1000000000
//Code starts here

struct triple
{
    int first, second, id;
};

struct cmp
{
    bool operator()(const triple &a, const triple &b)
    {
        int c1 = a.s-a.f;
        int c2 = b.s-b.f;
        if(c1 > 0 && c2 > 0)
            return a.f < b.f;
        if(c1 > 0 && c2 <= 0)
            return true;
        if(c1 <= 0 && c2 > 0)
            return false;
        if(c1 <= 0 && c2 <= 0)
            if(a.s == b.s)
                return a.f < b.f;
            else
                return a.s > b.s;
    }
};

void end()
{
    puts("NIE");
    exit(0);
}

int main()
{
    //TEST("testy_boh/tak/2.txt");
    int n,z,a,b;
    scanf("%d%d", &n, &z);
    vector<triple> tab;
    triple tmp;
    FOR(i, n)
    {
        tmp.id = i;
        scanf("%d %d", &tmp.f, &tmp.s);
        //daje zysk
        tab.PB(tmp);
    }
    sort(ALL(tab),cmp());
    //FOREACH(it, tab) printf("%d %d\n", it->f, it->s);
    //FOREACH(it, tab2) printf("%d %d\n", it->f, it->s);
    int res[n], cost;
    FOR(i, n)
    {
        cost = tab[i].s-tab[i].f;
        //print(cost);
        if(tab[i].f >= z || z < 1) end();
        z += cost;
        res[i] = tab[i].id+1;
    }

    puts("TAK");
    FOR(i, n) printf("%d ", res[i]);
}