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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "bits/stdc++.h"
using namespace std ;
#define endl "\n"
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N, K; 
    cin >> N >> K; 
    vector<int> Liczby(N); 
    int Max_In = 0;
    int Min_In = 0; 
    int Max = 0; 
    
    for(int i = 0; i < N; i++){
        cin >> Liczby[i] ; 
        if(Liczby[i] > Max){
            Max = Liczby[i]; 
            Max_In = i; 
        }
    } 
    int Min = Liczby[N - 1]; 
    for(int i = N - 2; i >= 0; i--){
        if(Liczby[i] < Min){
            Min = Liczby[i]; 
            Min_In = i; 
        }
    }
    int x = 0; 
    int y = 0; 
    for(int i = 0; i < N - 1; i++){
        if(Liczby[i] >= Liczby[i+1]){
            x = i; 
            y = i+1; 
            break; 
        }
    }
        
    if(K >= 3 && Max_In != N-1 && Max_In != 0){
        cout << "TAK" << endl; 
        int pom = K - 3;
        for(int i = 1; i < Max_In; i++){
            if(pom > 0){
                cout << i <<" "; 
            }
            pom--; 
        }
        cout << Max_In <<" "<< Max_In + 1<<" ";
        int pom1 = Max_In + 2;
         while(pom > 0){
            cout << pom1 <<" "; 
            pom--; 
            pom1++; 
        }
        return 0;
    }
    else if(K >= 3 && Max_In == 0){
        cout << "TAK" << endl; 
        cout << 1 <<" "; 
        int pom = K - 2;
        int j = 2; 
        while(pom > 0){
            cout << j <<" ";
            j++; 
            pom--;
        }
        return 0;
    }
    else if(K >= 3 && Max_In == N-1 && Min_In != 0){
        cout << "TAK" << endl;     
        int pom = K - 3;
        for(int i = 1; i < Min_In; i++){
            if(pom > 0){
                cout << i <<" "; 
            }
            pom--; 
        }
        cout << Min_In <<" "<< Min_In + 1<<" ";
        int pom1 = Min_In + 2;
         while(pom > 0){
            cout << pom1 <<" "; 
            pom--; 
            pom1++; 
        }
        return 0;
    }
    else if(K >= 4 && Max_In == N-1 && Min_In == 0 && x > 0 && y > 0){
        cout << "TAK" << endl;
       int pom = K - 4;
       for(int i = 1; i < x; i++){
            if(pom > 0){
                cout << i <<" "; 
            }
            pom--; 
        }
        cout << x <<" "<< y <<" "<< y + 1 <<" ";
        int pom1 = y + 2;
         while(pom > 0){
            cout << pom1 <<" "; 
            pom--; 
            pom1++; 
        }
        return 0;
    }
    else if(K == 3 && Max_In == N-1 && Min_In == 0){
            cout << "NIE" << endl; 
            return 0;
    }
    else if(K >= 4 && Max_In == N-1 && Min_In == 0 && x == 0 && y == 0){
        cout << "NIE" << endl;
        return 0;
    }
    else if(K == 2){
        if(Max_In == N -1){
                cout << "NIE" << endl; 
                return 0; 
            }
            if(Max_In == 0){
                cout <<"TAK" << endl; 
                cout << 1 << endl;
                return 0;
            }
            if(Max_In != 0 && Max_In != N -1){
                int min = Liczby[0]; 
                for(int i = 1; i <= Max_In; i++){
                    if(Liczby[i] < min){
                        min = Liczby[i];
                    }
                }
                int k = Max_In + 1;
                while(k < N){
                    int l = 0;
                    for(int z = k; z < N; z++){
                        if(Liczby[z] > min){
                            l++;
                        }
                    }
                    if(l == 0){
                        cout <<"TAK"<< endl;
                        cout << k << endl;
                        return 0; 
                    }
                    if(Liczby[k] < min){
                        min = Liczby[k];
                    }
                    k++;
                }
                cout << "NIE" << endl; 
                return 0;
            }
    }
}