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

using namespace std;

bool is_increasing(int n, vector<int> &arr)
{
    for (int i = 1; i < n; ++i)
    {
        if (arr[i] <= arr[i - 1]) return false;
    }
    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;

    vector<int> arr(n);
    for (int i = 0; i < n; ++i) cin >> arr[i];

    if (is_increasing(n, arr))
    {
        cout << "NIE";
        return 0;
    }

    if (k >= 4)
    {
        cout << "TAK\n";
        int pos = 0;
        while (arr[pos + 1] > arr[pos]) ++pos;

        k -= 3;
        if (pos != 0 && pos != -1) --k;

        for (int i = 1; i < pos && k; ++i)
        {
            cout << i << " ";
            --k;
        }

        if (pos) cout << pos << " ";
        cout << pos + 1 << " ";
        if (pos != n - 1) cout << pos + 2 << " ";

        for (int i = pos + 3; i <= n && k; ++i)
        {
            cout << i << " ";
            --k;
        }
    }
    else if (k == 3)
    {
        int maxi = arr[n - 1];
        int maxpos = n - 1;

        for (int i = n - 2; i >= 0; --i)
        {
            if (arr[i] >= maxi)
            {
                maxi = arr[i];
                maxpos = i;
            }
        }

        if (maxpos != n - 1)
        {
            cout << "TAK\n";
            if (!maxpos) cout << "1 2";
            else cout << maxpos << " " << maxpos + 1;
            return 0;
        }

        int mini = arr[0];
        int minpos = 0;

        for (int i = 1; i < n; ++i)
        {
            if (arr[i] <= mini)
            {
                mini = arr[i];
                minpos = i;
            }
        }

        if (minpos)
        {
            cout << "TAK\n";
            if (minpos == n - 1) cout << n - 2 << " " << n - 1;
            else cout << minpos << " " << minpos + 1;
            return 0;
        }

        cout << "NIE";
    }
    else
    {
        vector<int> left(n);
        vector<int> right(n);
        left[0] = arr[0];
        right[n - 1] = arr[n - 1];

        for (int i = 1; i < n; ++i) left[i] = min(arr[i], left[i - 1]);
        for (int i = n - 2; i >= 0; --i) right[i] = max(arr[i], right[i + 1]);

        for (int i = 1; i < n; ++i)
        {
            if (left[i - 1] >= right[i])
            {
                cout << "TAK\n" << i;
                return 0;
            }
        }
        cout << "NIE";
    }
}