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

using namespace std;

struct TestCase
{
  size_t n, k;
  vector<size_t> values;
};

TestCase read_test_case();
void solve_test_case(const TestCase&);

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve_test_case(read_test_case());
}

TestCase read_test_case()
{
  TestCase tc;
  cin >> tc.n >> tc.k;
  tc.values.resize(tc.n);
  for (auto& v : tc.values) cin >> v;
  return tc;
}

void solve_2(const TestCase& tc);
void solve_3(const TestCase& tc);
void solve_4_plus(const TestCase& tc);

void solve_test_case(const TestCase& tc)
{
  if (tc.k == 2)
    solve_2(tc);
  else if (tc.k == 3)
    solve_3(tc);
  else
    solve_4_plus(tc);
}

void solve_2(const TestCase& tc)
{
  vector<size_t> prefix_min(tc.n);
  vector<size_t> suffix_max(tc.n);

  prefix_min[0] = tc.values[0];
  suffix_max[tc.n - 1] = tc.values[tc.n - 1];

  for (size_t i = 1; i < tc.n; i++)
    prefix_min[i] = min(tc.values[i], prefix_min[i - 1]);

  for (size_t i = tc.n - 1; i > 0; i--)
    suffix_max[i - 1] = max(tc.values[i - 1], suffix_max[i]);

  for (size_t i = 1; i < tc.n; i++)
  {
    if (prefix_min[i - 1] >= suffix_max[i])
    {
      cout << "TAK\n";
      cout << i << "\n";
      return;
    }
  }

  cout << "NIE\n";
}

void solve_3(const TestCase& tc)
{
  size_t min_value = tc.values[0];
  size_t min_index = 0;

  size_t max_value = tc.values[tc.n - 1];
  size_t max_index = tc.n - 1;

  for (size_t i = 0; i < tc.n; i++)
    if (tc.values[i] <= min_value)
    {
      min_value = tc.values[i];
      min_index = i;
    }

  for (int i = tc.n - 1; i >= 0; i--)
    if (tc.values[i] >= max_value)
    {
      max_value = tc.values[i];
      max_index = i;
    }

  if (min_index == 0 && max_index == tc.n - 1)
  {
    cout << "NIE\n";
    return;
  }

  cout << "TAK\n";

  if (min_index != 0)
  {
    if (min_index == tc.n - 1)
      cout << tc.n - 2 << " " << tc.n - 1 << "\n";
    else
      cout << min_index << " " << min_index + 1 << "\n";
  }
  else
  {
    if (max_index == 0)
      cout << 1 << " " << 2 << "\n";
    else
      cout << max_index << " " << max_index + 1 << "\n";
  }
}

vector<size_t> clean_ends(const vector<size_t>& ends, size_t N);

void solve_4_plus(const TestCase& tc)
{
  vector<size_t> ends;

  for (size_t i = 1; i < tc.n; i++)
  {
    if (tc.values[i] <= tc.values[i - 1])
    {
      ends.push_back(i - 1);
      ends.push_back(i);
      ends.push_back(i + 1);
      break;
    }
  }

  if (ends.size() == 0)
  {
    cout << "NIE\n";
    return;
  }

  ends = clean_ends(ends, tc.n);

  vector<size_t> final_ends;

  for (size_t i = 1; i < ends[0]; i++)
  {
    if (final_ends.size() + ends.size() == tc.k - 1)
      break;
    else
      final_ends.push_back(i);
  }

  for (auto e : ends) final_ends.push_back(e);

  for (size_t i = ends.back() + 1; i < tc.n; i++)
    if (final_ends.size() == tc.k - 1)
      break;
    else
      final_ends.push_back(i);

  cout << "TAK\n";

  for (auto e : final_ends) cout << e << " ";
  cout << "\n";
}

vector<size_t> clean_ends(const vector<size_t>& ends, size_t N)
{
  vector<size_t> clean;
  for (auto e : ends)
    if (e != 0 && e != N) clean.push_back(e);
  return clean;
}