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

const int N = 500001, I = INT_MAX;
int n, k, tab[N];
vector <int> V;

int main(){
	ios_base::sync_with_stdio(0);
	cin>>n>>k;
	for (int i=1; i<=n; i++){
		cin>>tab[i];
	}
	V.push_back(n);
	int mn = tab[n], mx = tab[n], l = 1, prevmx=I, prevmn = -I;
	for (int i = n - 1; i>=1; i--){
		if (k-l == 1){
			V.push_back(i);
			break;
		}
		else if (tab[i]>mx){
			V.push_back(i);
			prevmx = tab[i], prevmn = tab[i];
			l++;
			i--;
			V.push_back(i);
			if (k-l == 1){
				break;
			}
			else mn = tab[i], mx = tab[i];
			l++;
		}
		else{
			mn = min(mn, tab[i]);
			mx = max(mx, tab[i]);
		}
	}
	V.push_back(0);
	
	bool g = 0;
	prevmn = 0, prevmx = 0, mn = I;
	for (int j = V.size()-1; j>0; j--){
		for (int i=V[j]+1; i<=V[j-1]; i++){
			if (tab[i] > prevmn && tab[i]<mn){
				mn = tab[i];
			}
		}
		if (mn==I){
			g = 1;
			break;
		}
		prevmn = mn;
		mn = I;
	}
	
	if (g){ 
		cout<<"TAK\n";
		for (int i=(int)V.size()-2; i>0; i--)
			cout<<V[i]<<" ";
		cout<<"\n";
	}
	else cout<<"NIE\n";
}