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
#include <iostream>
using namespace std;

const int MAXN = 5e5+1;

int a[MAXN], mx[MAXN+1], mn[MAXN];

int main(){
	int n, k;
	cin >> n >> k;
	for (int i=1; i<=n; i++) cin >> a[i];
	
	mn[0] = 1e9+1;
	for (int i=1; i<=n; i++) mn[i] = min(mn[i-1], a[i]);
	for (int i=n; i>=1; i--) mx[i] = max(mx[i+1], a[i]);
	if (k>n){cout << "NIE\n"; return 0;}
	else if (k==2){
		for (int i=1; i<=n-1; i++){
			if (mn[i] >= mx[i+1]){
				cout << "TAK\n";
				cout << i << "\n";
				return 0;
			}
		}
		cout << "NIE\n"; return 0;
	} else{
		for (int i=1; i<=n-1; i++){
			if (a[i] >= a[i+1]){
				if (k>3){
					cout << "TAK\n";
					int t=2;
					for (int j=1; j<i; j++){
						if (k-t){cout << j << " "; t++;}
						else break;
					}
					cout << i << " " << i+1 << " ";
					for (int j=i+2; j<=n; j++){
						if (k-t){cout << j << " "; t++;}
						else break;
					}
					return 0;
				} else{
					if (a[i]>=mx[i+1] || mn[i-1]>=a[i+1]){
						cout << "TAK\n";
						if (a[i]>=mx[i+1]){
							if (i==1) cout << i << " " << i+1 << "\n";
							else cout << i-1 << " " << i << '\n';
						} else if (mn[i]>=a[i+1]) cout << i << " " << i+1 << "\n";
						return 0;
					}
				}
			}
		}
		cout << "NIE\n";
		return 0;
	}
	cout << "NIE\n";
}