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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>

using namespace std;

int main(){
    int n, k, maks, min, a, flag = 0;
    int MIN;
    vector<int> pozycje;
    int tab[500000];
    cin >> n >> k;
    
    cin >> a;
    tab[0] = a;
    maks = a;
    min = a;
    MIN = a;
    pozycje.push_back(0);

    cin >> a;
    tab[1] = a;
    if(a > maks){
        maks = a;
    }
    else {
        flag = 1;
        min = a;
        if(a == MIN)
            pozycje.push_back(1);
        else if(a < MIN){
            pozycje.clear();
            pozycje.push_back(1);
            MIN = a;
        }
    }
    
    for(int i = 2; i < n; i++){
        cin >> a;
        tab[i] = a;
        if(flag == 0){
            if(a <= maks){
                flag = -1;
            }
            else{
                maks = a;
            }
        }
        else if(flag == 1){
            if((a > maks)||(a > min)){
                flag = -1;
            }
            else if(a < min){
                min = a;
            }
        }

        if(a == MIN){
            pozycje.push_back(i);
        }
        else if(a < MIN){
            MIN = a;
            pozycje.clear();
            pozycje.push_back(i);
        }
    }

    if(flag == 0){
        cout << "NIE" << endl;
    }
    else{
        if(flag == 1){
            cout << "TAK" << endl;
            for(int i = 1; i < k; i++){
                cout << i << " ";
            }
            cout << endl;
        }
        else{
            vector<int>::iterator it = pozycje.begin();
            vector<int>::iterator it2 = pozycje.begin();
            while (it != pozycje.end())
            {
                if(it + 1 == pozycje.end())
                    break;
                it++;
            }
            if(*it == n-1){
                cout << "TAK" << endl;
                stack<int> S;
                int x = *it;
                x++;
                k--;
                while(k > 0){
                    S.push(x);
                    x--;
                    k--;
                }
                while (!S.empty())
                {
                    cout << S.top() << " ";
                    S.pop();
                }
                cout << endl;
            }
            else if(*it2 == 0){
                if(k == 2){
                    cout << "NIE" << endl;
                }
                else{
                    int MAX = tab[1];
                    int posmax = 1;
                    for(int i = 2; i < n; i++){
                        if(tab[i] > MAX){
                            MAX = tab[i];
                            posmax = i;
                        }
                    }
                    if(posmax == n-1){
                        cout << "NIE" << endl;
                    }
                    else{
                        cout << "TAK" << endl;
                        vector<int> V;
                        k--;
                        int j = 1;
                        int b = 0;
                        V.push_back(posmax);
                        while(k > 1){
                            if(b == 0){
                                if(posmax+j <= n){
                                    V.push_back(posmax+j);
                                    k--;
                                }
                                b = 1;
                            }
                            else{
                                if(posmax-j > 0){
                                    V.push_back(posmax-j);
                                    k--;
                                }
                                j++;
                                b = 0;
                            }
                        }
                        sort(V.begin(), V.end());
                        it = V.begin();
                        while (it != V.end())
                        {
                            cout << *it << " ";
                            it++;
                        }
                        cout << endl;
                    }
                }
            }
            else{
                if(k == 2){
                    it = pozycje.begin();
                    int lmin = tab[0], rmax = tab[(*it)+1];
                    for(int i = 1; i < *it; i++){
                        if(tab[i] < lmin){
                            lmin = tab[i];
                        }
                    }
                    for(int i = (*it)+2; i < n; i++){
                        if(tab[i] > rmax){
                            rmax = tab[i];
                        }
                    }
                    if(lmin < rmax){
                        cout << "NIE" << endl;
                    }
                    else{
                        cout << "TAK" << endl;
                        cout << *it << endl;
                    }
                }
                else{
                    cout << "TAK" << endl;
                    vector<int> V;
                    k--;
                    it = pozycje.begin();
                    int j = 1;
                    int b = 0;
                    V.push_back(*it);
                    while(k > 1){
                        if(b == 0){
                            if((*it)+j <= n){
                                V.push_back((*it)+j);
                                k--;
                            }
                            b = 1;
                        }
                        else{
                            if((*it)-j > 0){
                                V.push_back((*it)-j);
                                k--;
                            }
                            j++;
                            b = 0;
                        }
                    }
                    sort(V.begin(), V.end());
                    it = V.begin();
                    while (it != V.end())
                    {
                        cout << *it << " ";
                        it++;
                    }
                    cout << endl;
                }
            }
        }
    }
    
    return 0;
}