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

void win(std::set<int> indices, int groups) {
    printf("TAK\n");
    int i = 1;
    while (indices.size() < groups - 1) {
        indices.insert(i);
        i += 1;
    }
    for (const auto ndx : indices) {
        printf("%d ", ndx);
    }
    printf("\n");
}

int main() {
    int size;
    int groups;
    !scanf("%d %d", &size, &groups);

    std::vector<int> earnings;

    for (int i = 0; i < size; i++) {
        int next;
        !scanf("%d", &next);
        earnings.push_back(next);
    }

    if (size == 1 || groups == 1) {
        // Technically impossible, but welp
        printf("TAK\n");
        return 0;
    }

    std::map<int, int> left;
    std::map<int, int> right;
    left[earnings[0]] += 1;
    for (int i = 1; i < earnings.size(); i++) {
        right[earnings[i]] += 1;
    }

    std::set<int> indices;
    for (int i = 1; i < earnings.size(); i++) {
        // printf("lb %d rb %d\n", left.begin()->first, right.rbegin()->first);
        if (left.begin()->first >= right.rbegin()->first) {
            indices.insert(i);
            win(indices, groups);
            return 0;
        }
        int elm = earnings[i];
        right[elm] -= 1;
        if (right[elm] == 0) {
            right.erase(right.find(elm));
        }

        if (groups > 2) {
            if (left.begin()->first >= elm || elm >= right.rbegin()->first) {
                indices.insert(i);
                indices.insert(i + 1);
                win(indices, groups);
                return 0;
            }
        }

        left[elm] += 1;
    }

    printf("NIE\n");
    return 0;
}