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

using namespace std;
typedef long long ll;

constexpr int mSize = 5e5 + 5;
constexpr int oo = 1e9;

int tab[mSize];
int tabMi[mSize];
int tabMx[mSize];

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

    int n, k;

    cin >> n >> k;

    tabMi[0] = oo;
    tabMx[n + 1] = -oo;

    for (int i = 1; i <= n; i++)
    {
        cin >> tab[i];
        tabMi[i] = min(tabMi[i - 1], tab[i]);
    }

    for (int i = n; i > 0; i--)
        tabMx[i] = max(tabMx[i + 1], tab[i]);

    if (k == 2)
    {
        for (int i = 1; i < n; i++)
        {
            if (tabMi[i] >= tabMx[i + 1])
            {
                cout << "TAK\n";
                cout << i << '\n';
                return 0;
            }
        }

        cout << "NIE\n";
        return 0;
    }
    else if(k == 3)
    {
        for (int i = 2; i < n; i++)
        {
            if (tabMi[i - 1] >= tab[i] || tab[i] >= tabMx[i])
            {
                cout << "TAK\n";
                cout << i - 1 << ' ' << i << '\n';
                return 0;
            }
        }
        cout << "NIE\n";
        return 0;
    }
    else
    {
        for (int i = 1; i < n; i++)
        {
            if (tab[i] >= tab[i + 1])
            {
                cout << "TAK\n";
                k -= 2;

                for (int j = n; j > i + 1 && k; j--)
                {
                    cout << j << ' ';
                    --k;
                }
                cout << i + 1 << ' ' << i << ' ';
                for (int j = i - 1; j > 0 && k; j--)
                {
                    cout << j << ' ';
                    --k;
                }
                return 0;
            }
        }
        cout << "NIE\n";
    }

    return 0;
}