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
#include <iostream>
#include <vector>

using namespace std;
const int MAXN = 500000;

int n, k;
int tab[MAXN + 5];
vector<int> W;

void solve1()
{
	int ind1 = 0, ind2 = 0;
	bool b = 0;
	for (int i = 2; i <= n; i++)
	{
		if (tab[i] <= tab[i - 1])
		{
			b = 1;
			ind1 = i - 1;
			ind2 = i;
			break;
		}
	}
	if (!b)
	{
		cout << "NIE";
		return;
	}
	cout << "TAK\n";
	int m = k - 3, l = ind1 - 1;
	while (m != 0 && l > 0)
	{
		W.push_back(l);
		--l; --m;
	}
	for (int i = W.size() - 1; i >= 0; --i)
	{
		cout << W[i] << " ";
	}
	W.clear();
	cout << ind1 << " " << ind2 << " ";
	l = ind2 + 1;
	while (m != 0 && l <= n)
	{
		W.push_back(l);
		++l; --m;
	}
	for (int i = 0; i < W.size(); ++i)
	{
		cout << W[i] << " ";
	}
}

void solve2()
{
	int Max = 0, maxind = 0;
	for (int i = n; i > 0; --i)
	{
		if (tab[i] >= Max)
		{
			Max = tab[i];
			maxind = i;
		}
	}
	if (maxind == n)
	{
		int Min = 1e9 + 1, minind = 0;
		for (int i = 1; i <= n; ++i)
		{
			if (tab[i] <= Min)
			{
				Min = tab[i];
				minind = i;
			}
		}
		if (minind == 1)
		{
			cout << "NIE";
			return;
		}
		else
		{
			cout << "TAK\n" << minind - 1 << " " << minind;
			return;
		}
	}
	else if (maxind == 1)
	{
		cout << "TAK\n" << 1 << " " << 2;
		return;
	}
	else
	{
		cout << "TAK\n" << maxind - 1 << " " << maxind;
		return;
	}
}

int minPref[MAXN + 5];
int maxSuf[MAXN + 5];

void solve3()
{
	minPref[1] = tab[1];
	for (int i = 2; i <= n; ++i)
	{
		minPref[i] = min(tab[i], minPref[i - 1]);
	}
	for (int i = n; i > 0; --i)
	{
		maxSuf[i] = max(tab[i], maxSuf[i + 1]);
	}
	for (int i = 1; i <= n - 1; ++i)
	{
		if (minPref[i] >= maxSuf[i + 1])
		{
			cout << "TAK\n" << i;
			return;
		}
	}
	cout << "NIE";
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> tab[i];
	}
	if (k >= 4) solve1();
	else if (k == 3) solve2();
	else if (k == 2) solve3();
}