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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include<cstdio>

#define N 500005

int min[N];
int max[N];
int tab[N];

int main() {
	int n, k;

	bool print = true;// TODO: powinno byc true

	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++) {
		scanf("%d", &tab[i]);
	}

	min[0] = tab[0];
	for (int i = 1; i < n; i++) {
		min[i] = min[i-1] < tab[i] ? min[i-1] : tab[i];
	}

	if (k == 2) {
		max[n-1] = tab[n-1];
		for (int i = n-2; i >= 0; i--) {
			max[i] = max[i+1] > tab[i] ? max[i+1] : tab[i];
		}
	} else if (k == 3) {
		max[n-2] = tab[n-2];
		for (int i = n-3; i >= 0; i--) {
			max[i] = max[i+1] > tab[i] ? max[i+1] : tab[i];
		}
	}

	if (k == 2) {
		bool found = false;
		int result;

		for (int i = 0; i < n-1; i++) {
			if (min[i] >= max[i+1]) {
				found = true;
				result = i + 1;
				break;
			}
		}

		if (found) {
			printf("TAK\n");
			if (print) {
				printf("%d\n", result);
			}
		} else {
			printf("NIE\n");
		}
	} else if (k == 3) {
		int max_value = tab[0];
		int max_index = 0;

		for (int i = 1; i < n; i++) {
			if (tab[i] > max_value) {
				max_value = tab[i];
				max_index = i;
			}
		}

		if (max_index == n - 1) {
			bool found = false;
			int result;

			for (int i = 0; i < n-2; i++) {
				if (min[i] >= max[i+1]) {
					found = true;
					result = i + 1;
					break;
				}
			}

			if (found) {
				printf("TAK\n");
				if (print) {
					printf("%d %d\n", result, n-1);
				}
			} else {
				printf("NIE\n");
			}


		} else {
			printf("TAK\n");
			if (print) {
				if (max_index == 0) {
					printf("%d %d\n", max_index+1, max_index+2);
				} else {
					printf("%d %d\n", max_index, max_index+1);
				}

			}
		}
	} else {
		bool isNieporzadek = false;
		int index;

		for (int i = 0; i < n - 1; i++) {
			if (tab[i] >= tab[i+1]) {
				isNieporzadek = true;
				index = i;
				break;
			}
		}

		if (isNieporzadek) {
			printf("TAK\n");
			if (print) {
				if (index == 0) {
					for (int i = 1; i < k; i++) {
						printf("%d ", i);
					}
				} else if (index == n - 2) {
					for (int i = n + 1 - k; i < n; i++) {
						printf("%d ", i);
					}
				} else {
					int s = k - 4;
					int t = index - s;
					if (t <= 1) {
						t = 1;
					}

					for (int i = t; i < t + k - 1; i++) {
						printf("%d ", i);
					}
				}
			}
		} else {
			printf("NIE\n");
		}
	}

	return 0;
}