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
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 5e5, inf = 1e9 + 7;
int n, k, a[NMAX + 7];
int pref[NMAX + 7], suf[NMAX + 7];
int32_t main() {
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    if (k == 2) {
        pref[0] = inf;
        for (int i = 1; i <= n; i++) pref[i] = min(pref[i - 1], a[i]);
        for (int i = n; i >= 1; i--) suf[i] = max(suf[i + 1], a[i]);
        for (int i = 1; i < n; i++) {
            if (pref[i] >= suf[i + 1]) {
                cout << "TAK\n"
#ifndef DEBUG
                     << i;
#else
                    ;
#endif
                return 0;
            }
        }
        cout << "NIE\n";
    } else if (k == 3) {
        int mini = 2, maxi = 2;
        for (int i = 3; i < n; i++) {
            if (a[mini] > a[i]) mini = i;
            if (a[maxi] < a[i]) maxi = i;
        }
        int j;
        if (a[mini] <= a[1]) {
            j = mini;
        } else if (a[maxi] >= a[n]) {
            j = maxi;
        } else {
            cout << "NIE";
            return 0;
        }
        cout << "TAK\n"
#ifndef DEBUG
             << j - 1 << " " << j << " ";
#else
            ;
#endif

    } else {
        int j = 0;
        for (int i = 1; i < n; i++) {
            if (a[i] >= a[i + 1]) {
                j = i;
                break;
            }
        }
        if (!j) {
            cout << "NIE\n";
            return 0;
        }
        cout << "TAK\n";
#ifndef DEBUG
        k -= 4;
        for (int x = 1; x < j - 1 && k; x++, k--) cout << x << " ";
        cout << j - 1 << " " << j << " " << j + 1 << " ";
        for (int x = j + 2; x < n && k; x++, k--) cout << x << " ";
#endif
    }
    return 0;
}
// DAWID PAWELEC