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

class Mob
{
public:
    Mob(int damage, int drop, int index) :
        damage_(damage), 
        drop_(drop),
        index_(index)
    {
    }
    
    long long getDiff() const {
        return (long long)(drop_) - damage_;
    }

    int getDamage() const {
        return damage_;
    }

    int getIndex() const {
        return index_;
    }

    bool operator< (Mob right) const
    {
        return drop_ > right.drop_;
    }
private:
    int damage_, drop_, index_;
};


struct divide
{
    bool operator() (Mob mob) const
    {
        return mob.getDiff() > 0LL;
    }
};

struct noobs
{
    bool operator() (Mob lhs, Mob rhs) const
    {
        return lhs.getDamage() < rhs.getDamage();
    }
};

using std::vector;

int main()
{
    int n;
    long long life;
    scanf("%d %lld", &n, &life);
    vector<Mob> v;
    v.reserve(n);

    for (int i = 1 ; i <= n ; i++)
    {
        int damage, drop;
        scanf("%d %d", &damage, &drop);
        v.push_back(Mob(damage, drop, i));
    }
    typedef vector<Mob>::iterator iterator;
    std::sort(v.begin(), v.end(), noobs()); 
    iterator bosses = partition(v.begin(), v.end(), divide()); 
    std::sort(bosses, v.end()); 
    
    vector<int> result;
    
    for (iterator it = v.begin(); it != v.end(); ++it)
    {
        if (life > it->getDamage())
        {
            life += it->getDiff();
            result.push_back(it->getIndex());
        }
        else
        {
            printf("NIE\n");
            return 0;
        }
    }
    printf("TAK\n");
    for (int i = 0 ; i < n ; i++)
    {
        printf("%d ", result[i]);
    }



}