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
//
// Jan Zachar, 14/12/2022
//
#include <iostream>
using namespace std;



int n, k;
int a;

int tab[5000001]{};
int amax[5000001]{};
int amin[5000001]{};

int nextk;
int maxg;
int prevmax;

struct {
    int data[5000001]{};
    int lasti;

    constexpr void push_back(int i) {data[lasti++] = i;}
} ktab;

int cntr;
bool badflag = true;

int main() {
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);

    cin >> n >> k;
    k--;

    amin[n+1] = INT32_MAX;
    for (int i = 1; i <= n; i++) {
        cin >> tab[i];
        amax[i] = max(amax[i-1], tab[i]);
    }

    for (int i = n; i > 0; i--) {
        amin[i] = min(amin[i+1], tab[i]);
    }

    ktab.push_back(n);
    for (int i = n; i > 1; i--) {
        if (!k) break;
        if (amin[i-1] < amin[i] || amax[i-1] < amax[i]) {
            --k;
            ktab.push_back(i-1);
        }
    }

    nextk = ktab.lasti-1;
    for (int i = 1; i <= n; i++) {
        maxg = max(maxg, tab[i]);
        if (i == ktab.data[nextk]) {
            if (prevmax > maxg) {
                badflag = false;
                break;
            }

            prevmax = maxg;
            maxg = 0;
            nextk--;
        }
    }

    if (badflag) {
        cout << "NIE" << endl;
        return 0;
    }

    cout << "TAK" << endl;
    for (int i = ktab.lasti-1; i > 0; i--) {
        cout << ktab.data[i] << " ";
    }
    cout << endl;
}