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
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <vector>

void two(std::vector<uint64_t> &a) {
    std::vector<uint64_t> prefix(a.size());
    std::vector<uint64_t> suffix(a.size());

    prefix[0] = a[0];
    for (uint64_t i = 1; i < a.size(); ++i) {
        prefix[i] = std::min(a[i], prefix[i - 1]);
    }

    suffix[a.size() - 1] = a[a.size() - 1];
    for (int64_t i = a.size() - 2; i >= 0; --i) {
        suffix[i] = std::max(a[i], suffix[i + 1]);
    }

    for (uint64_t i = 0; i + 1 < a.size(); ++i) {
        if (prefix[i] >= suffix[i + 1]) {
            std::cout << "TAK\n" << i + 1 << "\n";
            return;
        }
    }

    std::cout << "NIE\n";
}

void three(std::vector<uint64_t> &a) {
    uint64_t min_i = 0;
    for (uint64_t i = 1; i < a.size(); ++i) {
        if (a[min_i] >= a[i]) { min_i = i; }
    }

    uint64_t max_i = a.size() - 1;
    for (uint64_t i = 0; i < a.size() - 1; ++i) {
        if (a[max_i] <= a[i]) { max_i = i; }
    }

    // TODO: Coś nie działa
    if (min_i != 0) {
        std::cout << "TAK\n" << min_i << " " << min_i + 1 << "\n";
    } else if (max_i != a.size() - 1) {
        std::cout << "TAK\n" << max_i << " " << max_i + 1 << "\n";
    } else {
        std::cout << "NIE\n";
    }
}

void more(uint64_t k, std::vector<uint64_t> &a) {
    uint64_t i = 0;
    for (;;) {
        if (i + 1 >= a.size()) {
            std::cout << "NIE\n";
            return;
        }
        else if (a[i] >= a[i + 1]) { break; }
        else { i += 1; }
    }

    uint64_t start = std::max(int64_t(i) + 4 - int64_t(k), int64_t(1));
    std::cout << "TAK\n";
    for (uint64_t i = 0; i < k - 1; ++i) {
        std::cout << start + i << " ";
    }
    std::cout << "\n";
}

int main() {
    uint64_t n, k;
    std::cin >> n >> k;

    std::vector<uint64_t> a(n);
    for (uint64_t i = 0; i < n; ++i) {
        std::cin >> a[i];
    }

    if (k == 2) {
        two(a);
    } else if (k == 3) {
        three(a);
    } else {
        more(k, a);
    }
}