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
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stdint.h>
#include <vector>

struct Monster
{
    bool operator<(const Monster & m) const {
        return damage < m.damage;
    }
    int damage;
    int elixir;
    int no;
};

struct MonsterReversComparer
{
    bool operator() (const Monster & a, const Monster & b) const {
        return a.damage > b.damage;
    }
};

int main(int argc, char* argv[])
{
    int z, n;

    std::vector<Monster> vect1, vect2;
    scanf("%d%d", &n, &z);
    for (int i = 0; i < n; ++i) {
        Monster m;
        m.no = i + 1;
        scanf("%d%d", &m.damage, &m.elixir);
        if (m.elixir > m.damage)
            vect1.push_back(m);
        else
            vect2.push_back(m);
    }

	MonsterReversComparer comp;
	
    std::sort(vect1.begin(), vect1.end());
    std::sort(vect2.begin(), vect2.end(), comp);

    for (int i = 0; i < vect1.size(); ++i) {
        Monster & m = vect1[i];
        if (z - m.damage <= 0) {
            printf("NIE");
            return 0;
        }
        z += (m.elixir - m.damage);
    }
    for (int i = 0; i < vect2.size(); ++i) {
        Monster & m = vect2[i];
        if (z - m.damage <= 0) {
            printf("NIE");
            return 0;
        }
        z += (m.elixir - m.damage);
    }
    printf("TAK\n");
    for (int i = 0; i < vect1.size(); ++i) {
        Monster & m = vect1[i];
        printf("%d ", m.no);
    }
    for (int i = 0; i < vect2.size(); ++i) {
        Monster & m = vect2[i];
        printf("%d ", m.no);
    }

	return 0;
}