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>

int prefmin[1000111], sufmax[1000111], t[1000111], rising[1000111];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  for (int i = 1; i <= n; i++) scanf("%d", &t[i]);

  prefmin[1] = t[1];
  for (int i = 2; i <= n; i++) prefmin[i] = std::min(prefmin[i-1], t[i]);

  sufmax[n] = t[n];
  for (int i = n-1; i > 0; i--) sufmax[i] = std::max(sufmax[i+1], t[i]);

  if (k == 2) {
    int result = -1;

    for (int i = 1; i < n; i++) {
      if (prefmin[i] >= sufmax[i+1]) {
        result = i;
        break;
      }
    }

    if (result == -1) printf("NIE\n");
    // else printf("TAK\n");
    else printf("TAK\n%d\n", result);
  }
  if (k == 3) {
    int result = -1;

    for (int i = 2; i < n; i++) {
      if (prefmin[i-1] < t[i] && t[i] < sufmax[i+1]) {}
      else {
        result = i;
        break;
      }
    }

    if (result == -1) printf("NIE\n");
    // else printf("TAK\n");
    else printf("TAK\n%d %d\n", result-1, result);
  }

  if (k > 3) {
    int result = -1;

    rising[1] = 0;
    for (int i = 2; i <= n; i++) {
      if (t[i-1] < t[i]) rising[i] = rising[i-1] + 1;
      else rising[i] = 0;
    }

    int risingLength = k - 2;

    for (int i = 1 + risingLength; i < n; i++) {
      if (prefmin[i - risingLength] < t[i - risingLength + 1] && rising[i] >= risingLength-1 && t[i] < sufmax[i+1]) {}
      else {
        result = i;
        break;
      }
    }

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

  }


  return 0;
}