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
#include <iostream>
#include <vector>
#include <algorithm>
#define ALL(v) begin(v), end(v)
using namespace std;

template<typename... T>
void answer(T... args) {
    cout << "TAK\n";
    ((cout << args << ' '), ...);
    cout << '\n'; 
    exit(0);
}

int main() {
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> T(n);
    for(auto &v:T)  cin >> v;
    if(k==2) {
        auto mins = T;
        for(int i=1;i<n;i++) mins[i] = min(mins[i-1],mins[i]);
        int mx = T[n-1];
        for(int i=n-2;i>=0;i--) {
            if(mx <= mins[i])    answer(i+1);
            mx = max(mx, T[i]);
        }
    } else if(k==3) {
        reverse(ALL(T));
        auto [mi,Mi] = minmax_element(ALL(T));
        if(int d = distance(T.begin(),mi); d != n - 1)  {
            if(d == 0)  answer(n-2,n-1);
            else answer(n-d-1,n-d);
        }
        if(int d = distance(T.begin(),Mi); d != 0) {
            if(d == n - 1) answer(1,2);
            else answer(n-d-1,n-d);
        }
    } else {
        int d = distance(T.begin(), adjacent_find(ALL(T),[](auto x, auto y){return x >= y;}));
        if(d != n) {
            cout << "TAK\n";
            int p = max(1,d+4-k);
            if(d == n-2) p--;
            for(int i=1;i<k;i++,p++)    cout << p << ' ';
            cout << '\n';
            return 0;
        }
    }
    cout << "NIE\n";
}