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

typedef pair<int,int> pii;

void solve() {
    int n, k;
    cin >> n >> k;

    vector<int> data(n);
    for (int& d : data) {
        cin >> d;
    }

    bool sol = false;
    vector<bool> res(n - 1);
    if (k == 2) {
        vector<int> maxSuf(n);
        maxSuf[n - 1] = data[n - 1];
        for (int i = n - 2;i >= 0;i--) {
            maxSuf[i] = max(maxSuf[i + 1], data[i]);
        }

        int minX = data[0];
        for (int i = 0;i < n - 1;++i) {
            minX = min(minX, data[i]);
            if (minX >= maxSuf[i + 1]) {
                sol = true;
                res[i] = true;
                k--;
                break;
            }
        }
    }
    else if (k == 3) {
        for (int i = 1;i < n - 1;++i) {
            if (data[i] <= data[0]) {
                sol = true;
                res[i - 1] = res[i] = true;
                k -= 2;
                break;
            }
        }

        if (!sol) {
            for (int i = n - 2;i > 0;i--) {
                if (data[i] >= data[n - 1]) {
                    sol = true;
                    res[i - 1] = res[i] = true;
                    k -= 2;
                    break;
                }
            }
        }
    }
    else {
        for (int i = 1;i < n;++i) {
            if (data[i] <= data[i - 1]) {
                sol = true;
                res[i - 1] = true, k--;
                if (i > 1)
                    res[i - 2] = true, k--;
                if (i < n - 1)
                    res[i] = true, k--;
                break;
            }
        }
    }

    if (!sol) {
        cout << "NIE\n";
        return;
    }

    cout << "TAK\n";
    for (int i = 0;i < n - 1;++i) {
        if (!res[i] && k > 1) res[i] = true, k--;
        if (res[i]) {
            cout << i + 1 << " ";
        }
    }
    cout << "\n";
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}