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
#include <iostream>

using namespace std;
long long n, k, tab[500005], maxi, mini, maxind, minind, minik[500005], maxik[500005];
int main()
{
    cin >> n >> k;
    for(int i = 1; i<n+1; i++){
        cin >> tab[i];
    }
    if(k == 3){
        mini = 1e9+25;
        for(int i = 1; i<n+1; i++){
            if(tab[i] >= maxi){
                maxind = i;
            }
            if(tab[i] <= mini){
                minind = i;
            }
            if(minind == 1 and maxind == n){

                cout << "NIE";

            }
            else{
                if(maxind != n){
                    cout << "TAK" << " ";
                    cout << maxind-1 << " " << maxind;
                }
                else{
                    cout << minind -1 << " " << minind;
                }
            }
        }

    }
    if(k >= 4){
        for(int i = 1; i<n; i++){
            if(tab[i]>= tab[i+1]){
                if(i+1<k-1){
                    cout << "TAK" << " ";
                    for(int j = 1; j<=i; j++){
                        cout << j << " ";
                    }
                    for(int j = n-(k-i-2) + 1; j<= n-1; j++){
                        cout << j << " ";
                    }
                    return 0;

                }
                else{
                    cout << "TAK" << " ";
                    for(int j = 1+(i+2-k); j<= i+1; j++){
                        cout << j  << " ";
                    }
                    return 0;
                }
                return 0;
            }
        }
        cout << "NIE";
        return 0;
    }
    if(k == 2){
        minik[0] = 1e9+9;
        for(int i = 1; i<n; i++){
            minik[i] = min(minik[i-1], tab[i]);
        }
        for(int i = n; i>= 1; i--){
            maxik[i] = max(maxik[i+1], tab[i]);
        }
        for(int i = 1; i<n; i++){
            if(minik[i] >= maxik[i+1]){
                cout << "TAK" << " ";
                cout << i;
                return 0;
            }
            else{
                cout << "NIE";
                return 0;
            }
        }


    }
    return 0;
}