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
#include <iostream>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    int t[n];
    bool isAscending = true;
    bool possible = false;
    int possibleI = 0;
    int descI = 0;
    int max = 0, maxI=0, minSoFar=1000*1000*1000+1;
    for (int i=0; i<n; i++)
    {
        cin >> t[i];
        if (i>0 && t[i] <= t[i-1])
        {
            isAscending = false;
            descI = i;
            if (descI == n-1)
                descI--;
        }
        if (t[i] > max)
        {
            max = t[i];
            maxI = i;
        }
        if (t[i] <= minSoFar)
        {
            if (i > 0)
            {
                possible = true;
                possibleI = i;
            }
            minSoFar = t[i];
        }

    }
    
    if (isAscending)
    {
        cout << "NIE" << endl;
        return 0;
    }
    
    if (k == 2)
    {
        int minFromLeft[n];
        int maxFromRight[n];
        
        int min = t[0];
        for (int i=0; i<n; i++)
        {
            if (min > t[i])
                min = t[i];
            minFromLeft[i] = min;
        }
        max = t[n-1];
        for (int i=n-1; i>=0; i--)
        {
            if (max < t[i])
                max = t[i];
            maxFromRight[i] = max;
        }
        
        possible = false;
        int resultI = 0;
        for (int i=0; i<n-1; i++)
            if (minFromLeft[i] >= maxFromRight[i+1])
            {
                possible = true;
                resultI = i+1;
            }
        if (possible)
        {
            cout << "TAK" << endl;
            cout << resultI << endl;
        }
        else
            cout << "NIE" << endl;
    }
    
    if (k == 3)
    {
        if (maxI != n-1)
        {
            cout << "TAK" << endl;
            if (maxI == 0)
                cout << "1 2" << endl;
            else
                cout << maxI << " " << maxI + 1 << endl;
        }
        else if (possible)
        {
            cout << "TAK" << endl;
            cout << possibleI << " " << possibleI + 1 << endl;
        }
        else
            cout << "NIE" << endl;
    }
    if (k > 3)
    {
        int result[k-1];
        cout << "TAK" << endl;
        int limit = k-3;
        for (int i=1; i<limit; i++)
        {
            result[i-1] = i;
            if (i == descI-1 || i == descI || i == descI+1)
                limit++;
        }
        if (limit == k-3)
        {
            result[k-4] = descI-1;
            result[k-3] = descI;
            result[k-2] = descI+1;
        }
        else if (limit == k-2)
        {
            result[k-3] = descI;
            result[k-2] = descI+1;
        }
        else if (limit == k-1)
            result[k-2] = descI+1;
        for (int i=0; i<k-2; i++)
            cout << result[i] << " ";
        cout << result[k-2] << endl;

    }
}