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

struct pot {
    int we, wy;
    int no;
};

bool cmp(pot const &p1, pot const &p2) {
    return (p1.wy >= p2.we);
}

int main() {
    int n, z;
    0 == scanf("%d %d", &n, &z);
    std::vector<pot> pp;
    pp.reserve(n);
    for (int i = 0; i < n; i++) {
        pot p;
        p.no = i + 1;
        int a, b;
        0 == scanf("%d %d", &a, &b);
        p.we = a - z + 1;
        p.wy = b - z + 1;
        pp.push_back(p);
    }

    std::sort(pp.begin(), pp.end(), cmp);

    bool good = true;
    if (pp[0].we > 0)
        good = false;
    else
        for (int i = 0; i < n - 1; i++)
            if (!cmp(pp[i], pp[i+1]))
               good = false;
    if (!good)
        printf("NIE\n");
    else {
        printf("TAK\n");
        for (int i = 0; i < n - 1; i++)
            printf("%d ", pp[i].no);
        printf("%d\n", pp[n - 1].no);
    }
    return 0;
}