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
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n,k;
    cin >> n >> k;
    vector<int> vals;
    vals.reserve(n);
    for (int i = 0; i < n; ++i) {
        int v;
        cin >> v;
        vals.push_back(v);
    }

    if (k == 2) {
        int lowest = vals[0];

        vector<int> right_max;
        right_max.resize(n);
        right_max[n-1] = vals[n-1];
        for (int i = n - 2; i >= 0; --i) {
            right_max[i] = max(right_max[i+1], vals[i]);
        }

        for (int i = 0; i < n-1; ++i) {
            lowest = min(lowest, vals[i]);
            
            if (right_max[i+1] <= lowest) {
                cout << "TAK" << endl << i + 1 << endl;
                return 0;
            }
        }
    } else if (k==3) {
        int first = vals[0];
        int last = *vals.rbegin();
        for (int i = 1; i < n - 1; ++i) {
            if (vals[i] <= first) {
                cout << "TAK" << endl;
                cout << i << " " << i + 1 << endl;
                return 0;
            }
        }
        for (int i = n - 2; i >= 1; --i) {
            if (vals[i] >= last) {
                cout << "TAK" << endl;
                cout << i << " " << i + 1 << endl;
                return 0;
            }
        }
    } else {
        int lower = -1;
        for (int i = 0; i < n - 1; ++i) {
            if (vals[i] >= vals[i + 1]) {
                lower = i + 2;
            }
        }

        if (lower == n) lower = n - 1;
        if (lower == 2) lower = 3;

        // RANDOM ... "lower-2" "lower - 1" "lower"
        if (lower != -1) {
            int ind = 1;
            k -= 1;

            cout << "TAK" << endl;

            while (k > 3 && ind != lower - 2) {
                cout << ind++ << " ";
                --k;
            }

            cout << lower - 2 << " " << lower - 1 << " " << lower << " ";

            ind = lower + 1;
            k -= 3;

            while (k) {
                cout << ind++ << " ";
                --k;
            }
            cout << endl;

            return 0;
        }
    }

    cout << "NIE" << endl;

    return 0;
}