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;

int n, k;
int t[500007];
int ma = 1, mi = 1, nros, b;
int maxsuf[500007];
int minpre[500007];

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

    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> t[i];
        if(t[ma] < t[i])
            ma = i;
        if(t[mi] >= t[i])
            mi = i;
        if(t[i] <= t[i-1])
            nros = i;
    }

    if(nros == n)
        b = 3;
    else
        b = 4;
    if(k >= b){
        if(!nros){
            cout << "NIE";
            return 0;
        } else{
            cout << "TAK\n";
        }
        for(int i = 1; i <= n; i++){
            if(k > b){
                cout << i << ' ';
                k--;
            } else if(k == b && i <= nros - 2){
                if(b == 4)
                    cout << nros - 2 << ' ' << nros - 1 << ' ' << nros;
                else
                    cout << nros - 2 << ' ' << nros - 1;
                break;
            } else if(k > 1){
                cout << i << ' ';
                k--;
                if(k == 1)
                    break;
            }
        }
        return 0;
    } else if(k == 3){
        if(mi == 1 && ma == n){
            cout << "NIE";
            return 0;
        } else if(mi != 1){
            cout << "TAK\n";
            if(mi == n)
                cout << n-2 << ' ' << n-1;
            else
                cout << mi-1 << ' ' << mi;
        } else if(ma != n){
            cout << "TAK\n";
            if(ma == 1)
                cout << 1 << ' ' << 2;
            else
                cout << ma-1 << ' ' << ma;
        }
    } else if(k == 2){
        minpre[1] = t[1];
        for(int i = 2; i <= n; i++)
            minpre[i] = min(t[i], minpre[i-1]);
        for(int i = n; i >= 1; i--)
            maxsuf[i] = max(t[i], maxsuf[i+1]);

        for(int i = 1; i < n; i++){
            if(minpre[i] >= maxsuf[i+1]){
                cout << "TAK\n" << i;
                return 0;
            }
        }
        cout << "NIE";
    }

return 0;
}