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
//Author:Karolina Miśkiewicz
#include<iostream>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int n, m;
	cin >> n >> m;
	int tab[n], nm[n];
	for(int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		tab[i] = a;
		if(i == 0)
			nm[i] = a;
		else
			nm[i] = min(nm[i-1],a);
	}

	if(m == 2)
	{
		int mini = tab[n-1];
		int p = -1;
		for(int i = n-1; i >= 0; i--)
		{
			if(nm[i] >= mini) //you cannot go higher after
			{
				p = i;
				break;
			}
			else
				mini = max(tab[i], mini);
		}
		if(p == -1)
			cout << "NIE";
		else
			cout << "TAK" << "\n" << p;
	}
	else if(m == 3) // most complicated one, because you can have good option from front or back
	{
		 int p = -1;
		 int mini = tab[0];
		 for(int i = 1; i < n; i++)
		 {
		 	if(tab[i] <= mini)
			{
				p = i;
				break;
			}
		}

			if(p != -1)
			{
			if(p == n-1)
				cout << "TAK" << "\n" << "1 " << p;
			else
				cout << "TAK" << "\n" << p << " " << p+1;
			}
		 if(p == -1)
		 {
		 	mini = tab[n-1];
			for(int i = n-2; i >= 0; i--)
			{
				if(tab[i] >= mini)
				{
				p = i;
				break;
				}
			}

			if(p == -1)
				cout << "NIE";
			else
			{
                cout << "TAK" << "\n";
				if(p == 1)
					cout << p << " 2";
				else
					cout << p - 1 << " "  << p;
			}
		}
	}
	else // we have to just find two numbers where a >= b, then rest is not consequential
	{
		int p = -1;
		for(int i = 1; i < n; i++)
		{
			if(tab[i-1] >= tab[i])
			{	
				p = i;
				break;
			}
		}
		if(p != -1)
        {
            cout << "TAK" << "\n";
            if(p+1 <= m)
            {
                for(int i = 1; i < m; i++)
                    cout << i << " ";
            }
            else
            {
                for(int i = 1; i+2 < m; i++)
                    cout << i << " ";
                cout << p << " " << p+1;
            }
        }
        else
            cout << "NIE";
	}
}