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
#include <bits/stdc++.h>
using namespace std;

const int N = 505050;
int n, k, a[N], b[N], pmin[N], smax[N];
int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b + 1, b + 1 + n);

    if (b[1] == b[n]) {
        cout << "TAK\n";
        for (int i = 1; i < k; i++) {
            cout << i << ' ';
        }
        return 0;
    }
    bool f = true;
    for (int i = 1; i <= n; i++) {
        if (a[i] != b[i]) f = false;
    }
    if (f) {
        cout << "NIE";
        return 0;
    }
    if (k >= 3) {
        int p = 0, q = 0;
        for (int i = n; i >= 1; i--) {
            if (a[i] != b[i]) {
                p = b[i]; break;
            }
        }
        for (int i = 1; i <= n; i++) {
            if (a[i] == p) {
                q = i; break;
            }
        }
        cout << "TAK\n";
        set<int> ans = { q };
        if (q != 1) ans.insert(q - 1);
        
        for (int i = 1; i < n; i++) {
            if (ans.size() == k - 1) break;
            ans.insert(i);
        }
        for (int x : ans) {
            cout << x << ' ';
        }
    }
    else {
        pmin[1] = a[1]; smax[n] = a[n];
        for (int i = 2; i <= n; i++) {
            pmin[i] = min(pmin[i - 1], a[i]);
        }
        for (int i = n - 1; i >= 1; i--) {
            smax[i] = max(smax[i + 1], a[i]);
        }
        
        for (int i = 1; i < n; i++) {
            if (pmin[i] >= smax[i + 1]) {
                cout << "TAK\n" << i;
                return 0;
            }
        }
        cout << "NIE";        
    }
}