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
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, k;

	cin >> n >> k;
	--k;
	bool ok = false;
	vector <int> pod (n), odp;
	for (auto &i : pod)
		cin >> i;
	int i = n-1, j = n-1;
	//do {
	while (i >= 0 and k > 0) {
		if (k > i+1) { cout << "NIE"; return 0;}
		else
		if (k > i) {
			if (not ok)
				for (int ii = i; ii > 0; --ii)
				    if (pod[ii] <= pod[ii - 1]){
						ok = true;
						break;
					}
			if (ok) {
				cout << "TAK\n";
				for (int ii = 1; ii < k; ++ii)
					cout << ii << ' ';
					
				for (int ii{odp.size() - 1}; ii >= 0; --ii) 
				     cout << odp[ii] << ' ';
				
				return 0;
				 }
			 }
		--i;
		if (pod[i] >= pod[j]) {
			odp.push_back(i + 1);
			--k;
			if (k and i > 0) {
				odp.push_back(i);
				--k, --i;
			ok = true;
			
			}
			j = i;
		}
	}
	//cout << k << endl;
	if (not (ok and k==0)) cout << "NIE\n";
	else {
		cout << "TAK\n";
		for (int ii{odp.size() - 1}; ii >= 0; --ii) 
				     cout << odp[ii] << ' ';
				 }
}