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

void for_k23(std::vector<int> &tab, int k) {
    std::vector<int> prefix_min(tab.size(), 0);
    prefix_min[0] = tab[0];
    for (int i = 1; i < tab.size(); ++i)
        prefix_min[i] = std::min(prefix_min[i-1], tab[i]);
    std::vector<int> suffix_max(tab.size(), 0);
    suffix_max[tab.size()-1] = tab[tab.size()-1];
    for (int i = tab.size() - 2; i >= 0; --i)
        suffix_max[i] = std::max(suffix_max[i+1], tab[i]);

    if (k == 2) {
        for (int i = 1; i < tab.size(); ++i) {
            //fprintf(stderr, "idx:%d pmin:%d smax:%d\n", i, prefix_min[i], suffix_max[i]);
            if (prefix_min[i-1] >= suffix_max[i]) {
                printf("TAK\n%d\n", i); 
                return;
            }
        }
        printf("NIE\n");
    } else { // k == 3
        for (int i = 1; i < tab.size()-1; ++i) {
            //printf("idx:%d pmin:%d smax:%d\n", i, prefix_min[i], suffix_max[i]);
            if (prefix_min[i] >= tab[i]) {
                printf("TAK\n%d %d\n", i, i+1); // koniec to i - 1, + 1 (index od 1)
                return;
            }
        }
        for (int i = 1; i < tab.size()-1; ++i) {
            //printf("idx:%d pmin:%d smax:%d\n", i, prefix_min[i], suffix_max[i]);
            if (suffix_max[i] <= tab[i]) {
                printf("TAK\n%d %d\n", i, i+1); // koniec to i - 1, + 1 (index od 1)
                return;
            }
        }

        printf("NIE\n");
    }
}

void for_big_k(std::vector<int> &tab, int k) {
    for (int i = 1; i < tab.size(); ++i) {
        if (tab[i-1] >= tab[i]) {
            printf("TAK\n");
            for (int j = 1; j < i-1 && j < k-2; ++j)
                printf("%d ", j);
            printf("%d ", i);
            printf("%d ", i+1);
            for (int j = i+2; j < k; ++j)
                printf("%d ", j);
            printf("\n");
            return;
        }
    }
    printf("NIE\n");
}

int main() {

    int n, k;
    scanf("%d %d", &n, &k);

    std::vector<int> tab(n);
    for (int i = 0; i < n; ++i)
      scanf("%d", &tab[i]);

    if (k <= 3) for_k23(tab, k);
    else for_big_k(tab, k);

    return 0;
}