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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// Witold Milewski
// Potyczki Algorytmiczne - 2022

#include <bits/stdc++.h>
using namespace std;

// numbers -> data
int *numbers;
// prefix -> minimum on prefix
int *prefix;
// sufix -> maximum on sufix
int *sufix;
// decrease -> is decreasing or equal (i and i+1)
bool *decrease;
// range_end -> is this element end of an range
bool *range_end;

void preprocess(int n) {
  // prefix
  prefix[1] = numbers[1];
  for (int i = 2; i <= n; i++) {
    prefix[i] = min(numbers[i], prefix[i - 1]);
  }

  // sufix
  sufix[n] = numbers[n];
  for (int i = n - 1; i >= 1; i--) {
    sufix[i] = max(numbers[i], sufix[i + 1]);
  }

  // is decreasing or equal
  for (int i = 1; i < n; i++) {
    if (numbers[i + 1] <= numbers[i]) decrease[i] = true;
    // cout << decrease[i] << " ";
  }
}

void failure() {
  cout << "NIE\n";
  exit(0);
}

void k2(int n, int k) {
  int insert = k - 1;

  for (int i = 1; i < n; i++) {
    if (!decrease[i]) continue;
    int min_v = prefix[i];
    int max_v = sufix[i + 1];
    // cout << i << " " << min_v << " " << max_v << '\n';
    if (max_v <= min_v) {
      range_end[i] = true;
      insert -= 1;

      // fill rest
      int j = 1;
      while (insert > 0 && j < n) {
        if (!range_end[j]) {
          range_end[j] = true;
          insert--;
        }
        j++;
      }

      if (insert > 0) failure();

      return;
    }
  }

  failure();
}

void k3(int n, int k) {
  int insert = k - 1;

  for (int i = 1; i < n; i++) {
    if (!decrease[i]) continue;

    // left
    if (i > 1) {
      int v_a_left = prefix[i - 1];
      int v_a_center = numbers[i];
      int v_a_right = sufix[i + 1];
      if (v_a_right <= v_a_center || v_a_center <= v_a_left) {
        range_end[i - 1] = true;
        range_end[i] = true;
        insert -= 2;

        // fill rest
        int j = 1;
        while (insert > 0 && j < n) {
          if (!range_end[j]) {
            range_end[j] = true;
            insert--;
          }
          j++;
        }

        if (insert > 0) k2(n, k);

        return;
      }
    }

    // right
    if (i <= n - 2) {
      int v_b_left = prefix[i];
      int v_b_center = numbers[i + 1];
      int v_b_right = sufix[i + 2];
      if (v_b_right <= v_b_center || v_b_center <= v_b_left) {
        range_end[i] = true;
        range_end[i + 1] = true;
        insert -= 2;

        // fill rest
        int j = 1;
        while (insert > 0 && j < n) {
          if (!range_end[j]) {
            range_end[j] = true;
            insert--;
          }
          j++;
        }

        if (insert > 0) k2(n, k);

        return;
      }
    }
  }

  k2(n, k);
}

void all(int n, int k) {
  int insert = k - 1;

  for (int i = 2; i < n - 1; i++) {
    if (!decrease[i]) continue;

    // fill important
    range_end[i - 1] = true;
    range_end[i] = true;
    range_end[i + 1] = true;
    insert -= 3;

    // fill rest
    int j = 1;
    while (insert > 0 && j < n) {
      if (!range_end[j]) {
        range_end[j] = true;
        insert--;
      }
      j++;
    }

    if (insert > 0) k3(n, k);

    return;
  }

  k3(n, k);
}

void success(int n) {
  cout << "TAK\n";
  for (int i = 1; i < n; i++) {
    if (!range_end[i]) continue;
    cout << i << " ";
  }
}

void run(int n, int k) {
  preprocess(n);

  // lewo -> min
  // prawo -> max
  if (k == 2)
    k2(n, k);
  else if (k == 3)
    k3(n, k);
  else if (k >= 4)
    all(n, k);

  success(n);
}

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);

  // n -> numbers amount
  // k -> ranges amount
  int n, k;
  cin >> n >> k;

  numbers = new int[n + 1];
  prefix = new int[n + 1];
  sufix = new int[n + 1];
  decrease = new bool[n + 1];
  range_end = new bool[n + 1];

  for (int i = 1; i <= n; i++) {
    cin >> numbers[i];
    decrease[i] = false;
    range_end[i] = false;
  }

  run(n, k);

  return 0;
}