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
#include <iostream>
  #include <stdio.h>
  using namespace std;


  static bool printPositions = true;

  int lowest(int a, int b) {
    return a < b ? a : b;
  }

  int highest(int a, int b) {
    return a > b ? a : b;
  }

  int main() {
    int n;
    cin >> n;
    int k;
    cin >> k;

    int money[n];
    for (int i = 0; i < n; i++) {
      cin >> money[i];
    }

    int leftLow[n];
    leftLow[0] = money[0];
    for (int i = 1; i < n; i++) {
      leftLow[i] = lowest(leftLow[i - 1], money[i]);
    }

    int rightHigh[n];
    rightHigh[n - 1] = money[n - 1];
    for (int i = n - 2; i > 0; i--) {
      rightHigh[i] = highest(rightHigh[i + 1], money[i]);
    }

    if (k == 2) {
      for (int i = 0; i < n - 1; i++) {
        if (leftLow[i] >= rightHigh[i + 1]) {
          printf("TAK\n");
          if (printPositions) {
            printf("%d\n", i + 1);
          }
          return 0;
        }
      }
      printf("NIE\n");
      return 0;
    }

    if (k == 3) {
      for (int i = 1; i < n - 1; i++) {
        if (leftLow[i - 1] >= money[i]
            || money[i] >= rightHigh[i + 1]) {
          printf("TAK\n");
          if (printPositions) {
            printf("%d %d\n", i, i + 1);
          }
          return 0;
        }
      }
      printf("NIE\n");
      return 0;
    }

    // k >= 4
    for (int i = 0; i < n - 1; i++) {
      if (money[i] >= money[i + 1]) {
        printf("TAK\n");
        if (printPositions) {
          if (i + 2 < k - 1) {
            i = k - 3;
          }
          if (i + 2 > n - 1) {
            i = n - 3;
          }
          for (int j = 1; j <= k - 4; j++) {
            printf("%d ", j);
          }
          printf("%d %d %d\n", i, i + 1, i + 2);
        }
        return 0;
      }
    }

    printf("NIE\n");
    return 0;
  }