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
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>

struct creature {
    int num;
    int down;
    int up;
};

bool weaker(creature c1, creature c2) {
    return c1.down < c2.down;
}

bool stronger_potion(creature c1, creature c2) {
    return c1.up > c2.up;
}

void failure() {
    printf("NIE\n");
    exit(0);
}

int main() {
    int n, health;
    std::vector <creature> easy, medium, hard;
    scanf("%d %d", &n, &health);
    for (int i=0; i<n; ++i) {
        creature c;
        c.num = i+1;
        scanf("%d %d", &c.down, &c.up);
        if (c.down > c.up) {
            hard.push_back(c);
        } else if (c.down < c.up) {
            easy.push_back(c);
        } else {
            medium.push_back(c);
        }
    }
    
    std::sort(easy.begin(), easy.end(), weaker);
    std::sort(hard.begin(), hard.end(), stronger_potion);

    int htemp = health;
    std::vector<creature> creatures[3] = {easy, medium, hard};
    for (int i=0; i<3; ++i) {
        std::vector<creature>::iterator it; 
        for (it=creatures[i].begin(); it!=creatures[i].end(); ++it) {
            htemp -= (*it).down;
            if (htemp <= 0) failure();
            htemp += (*it).up;
        }
    }

    printf("TAK\n");
    for (int i=0; i<3; ++i) {
        std::vector<creature>::iterator it; 
        for (it=creatures[i].begin(); it!=creatures[i].end(); ++it) {
            printf("%d ", (*it).num);
        }
    }
    printf("\n");
    return 0;
}