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
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k,i,minnp,j;
	pair <int,int> nm,nw;
	scanf("%d%d",&n,&k);
	int arr[n];
	int maxnp[n];
	for(i=0;i<n;i++)
		scanf("%d",&arr[i]);
	if(k==2){
		maxnp[n-1]=arr[n-1];
		for(i=n-2;i>=0;i--)
			maxnp[i]=max(maxnp[i+1],arr[i]);
		minnp=arr[0];
		for(i=0;i+1<n;i++){
			minnp=min(minnp,arr[i]);
			if(minnp>=maxnp[i+1]){
				printf("TAK\n%d\n",i+1);
				return 0;
			}
		}
	}
	else if(k==3){
		nm={arr[1],1};
		for(i=1;i<n;i++)
			nm=min(nm,{arr[i],i});
		nw={arr[n-2],n-2};
		for(i=0;i<n-1;i++)
			nw=max(nw,{arr[i],i});
		if(nm.first<=arr[0]){
			printf("TAK\n");
			if(nm.second==n-1)
				printf("%d %d\n",nm.second-1,nm.second);
			else
				printf("%d %d\n",nm.second,nm.second+1);
			return 0;
		}
		if(nw.first>=arr[n-1]){
			printf("TAK\n");
			if(nw.second==n-1)
				printf("%d %d\n",nw.second-1,nw.second);
			else
				printf("%d %d\n",nw.second,nw.second+1);
			return 0;
		}
	}
	else{
		for(i=0;i+1<n;i++)
			if(arr[i]>=arr[i+1]){
				printf("TAK\n");
				k--;
				if(i+1==n-1)
					k++;
				j=max(i-(k-2),0);
				while(k>2 && j<=i-1){
					printf("%d ",j+1);
					k--;
					j++;
				}
				printf("%d ",i+1);
				if(i+1<n-1)
					printf("%d ",i+2);
				k-=2;
				j=i+2;
				while(k){
					printf("%d ",j+1);
					k--;
					j++;
				}
				printf("\n");
				return 0;
			}
		
	}
	printf("NIE\n");
	return 0;
}