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

using namespace std;

int main () {
	int n,k;
	cin>>n>>k;
	int arr [n];
	for(int i = 0; i < n; i++) {
		int temp;
		cin>>temp;
		arr[i]=temp;
	}
	if(k==2) {
		int prefixmin [n];
		int suffixmax [n];
			int mini = 1000000001;
		for(int i = 0;i<n;i++) {
			if(arr[i]<mini) {
				prefixmin[i]=arr[i];
				mini=arr[i];
				//cout<<"mini>arr[i] for i "<<i<<", arr[i]= "<<arr[i]<<endl;
			}
			else {
				prefixmin[i]=prefixmin[i-1];
			}
		}
			int maxi=0;
		for(int i = n-1; i>-1;i--) {
			if(arr[i]>maxi) {
				suffixmax[i]=arr[i];
				maxi=arr[i];
			} else {
				suffixmax[i]=suffixmax[i+1];
			}
		}
		for(int i = 0;i<n-1;i++) {
			//cout<<"prefixmin: "<<prefixmin[i]<<", suffixmax: "<<suffixmax[i]<<endl;
			if(prefixmin[i]>=suffixmax[i+1]) {
				cout<<"TAK\n"<<i+1<<endl;
				return 0;
			}
		}
		cout<<"NIE\n";
	} else if (k==3) {
		int lastmin,mini=1000000001,firstmax,maxi=0;
		for(int i=0;i<n;i++) {
			int temp=arr[i];
			if(temp<=mini) {
				mini=temp;
				lastmin=i;
			} else if (temp>maxi) {
				maxi=temp;
				firstmax=i;
			}
		}
		//cout<<lastmin<<" "<<firstmax<<endl;
		if(lastmin>0) {
			cout<<"TAK\n"<<lastmin-1<<" "<<lastmin<<endl;
		} else if (firstmax<n-1) {
			cout<<"TAK\n"<<firstmax<<" "<<firstmax+1<<endl;
		}
	} else {
		int notmore;
		bool possible=false;
		for (int i = 1;i<n;i++) {
			if(arr[i]<=arr[i-1]) {
				notmore=i;
				possible=true;
			}
		}
		if(possible) {
			cout<<"TAK\n";
			int before=min(k-4,notmore-2);
			for(int i = 1;i<=before;i++) {
				cout<<i<<" ";
			}
			cout<<notmore-1<<" "<<notmore<<" "<<notmore+1<<" ";
			for(int i=before+3;i<k-1;i++) {
				cout<<i<<" ";
			}
		}
	}
}