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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 5e5 + 5;
const int inf = 0x3f3f3f3f;

int a[MAXN];

int main(void)
{
	int n,d;
	scanf("%d%d",&n,&d);
	for(int i=1; i<=n; ++i)
		scanf("%d",&a[i]);
	
	if(d >= 4)
	{
		for(int i=1; i<n; ++i) if(a[i] >= a[i+1])
		{
			static bool vis[MAXN];
			vis[i-1] = vis[i] = vis[i+1] = 1;
			
			int cnt = 0;
			for(int j=1; j<n; ++j)
				if(vis[j]) ++cnt;
			
			for(int j=1; j<n && cnt<d-1; ++j)
				if(!vis[j])
				{
					vis[j] = 1;
					++cnt;
				}
			
			printf("TAK\n");
			for(int j=1; j<n; ++j)
				if(vis[j])
					printf("%d ",j);
			return 0;
		}
		printf("NIE\n");
	}
	else if(d == 3)
	{
		int mn = *min_element(a+1, a+n+1);
		int mx = *max_element(a+1, a+n+1);
		
		for(int i=2; i<=n; ++i) if(a[i] == mn)
		{
			if(i != n)
				printf("TAK\n%d %d\n",i-1,i);
			else
				printf("TAK\n%d %d\n",i-2,i-1);
			return 0;
		}
		
		for(int i=1; i<=n-1; ++i) if(a[i] == mx)
		{
			if(i != 1)
				printf("TAK\n%d %d\n",i-1,i);
			else
				printf("TAK\n%d %d\n",1,2);
			return 0;
		}
		
		printf("NIE\n");
	}
	else if(d == 2)
	{
		static int pre[MAXN], suf[MAXN];
		pre[0] = inf; suf[n+1] = -inf;
		for(int i=1; i<=n; ++i)
			pre[i] = min(pre[i-1], a[i]);
		for(int i=n; i>=1; --i)
			suf[i] = max(suf[i+1], a[i]);
		
		for(int i=1; i<n; ++i)
			if(pre[i] >= suf[i+1])
			{
				printf("TAK\n%d\n",i);
				return 0;
			}
		
		printf("NIE\n");
	}
	return 0;
}