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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#define NDEBUG

using namespace std;

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    
    int n,k;
    cin >> n >> k;
    vector<int> a(n,0);
    for(int i=0; i<n; ++i)
    {
        cin >> a[i];
    }
    
    if(k==2)
    {
        vector<int> min_0_i(n,0);
        vector<int> max_i_n(n,0);
        min_0_i[0] = a[0];
        for(int i=1; i<n; ++i)
        {
            min_0_i[i] = min(min_0_i[i-1],a[i]);
        }
        max_i_n[n-1] = a[n-1];
        for(int i=n-2; i>=0; --i)
        {
            max_i_n[i] = max(max_i_n[i+1],a[i]);
        }
        for(int i=0; i<n-1; ++i)
        {
            if(min_0_i[i] >= max_i_n[i+1])
            {
                cout << "TAK\n";
                cout << i+1;
                return 0;
            }
        }
        cout << "NIE";
        return 0;
    }
    else if(k==3)// => n>=3
    {
        auto first_min_it = min_element(a.begin(),a.end());
        auto last_max_it = max_element(a.rbegin(),a.rend());
        int first_min_pos = first_min_it - a.begin();
        int last_max_pos = n-1 - (last_max_it - a.rbegin());
        if(first_min_pos!=0)
        {
            cout << "TAK\n";
            if(first_min_pos<n-1)
            {
                cout << first_min_pos-1+1 << " " << first_min_pos+1;
            }
            else
            {
                cout << first_min_pos-2+1 << " " << first_min_pos-1+1;
            }
            return 0;
        }
        
        if(last_max_pos!=n-1)
        {
            cout << "TAK\n";
            if(last_max_pos>0)
            {
                cout << last_max_pos-1+1 << " " << last_max_pos+1;
            }
            else
            {
                cout << last_max_pos+1 << " " << last_max_pos+1+1;
            }
            return 0;
        }
        
        int target_pos = -1;
        for(int i=1; i<n-1; ++i)
        {
            if(a[i]==a[first_min_pos] || a[i]==a[last_max_pos])
            {
                target_pos = i;
                break;
            }
        }
        if(target_pos==-1)
        {
            cout << "NIE";
            return 0;
        }
        else
        {
            cout << "TAK\n";
            cout << target_pos-1+1 << " " << target_pos+1;
            return 0;
        }
    }
    else
    {
        int first_id=0, second_id=0;
        for(int i=1; i<n; ++i)
        {
            if(a[i-1]>=a[i])
            {
                first_id = i-1;
                second_id = i;
                break;
            }
        }
        if(first_id==second_id) // a is strictly increasing sequence
        {
            cout << "NIE";
            return 0;
        }
        
        
        cout << "TAK\n";
        vector<int> range_ends(n,0);
        int todo = k-1;
        if(first_id>0)
        {
            range_ends[first_id-1] = true;
            --todo;
        }
        range_ends[first_id] = true;
        --todo;
        if(second_id<n-1)
        {
            range_ends[second_id] = true;
            --todo;
        }
        if(todo>0)
        {
            for(int i=0; i<n; ++i)
            {
                if(!range_ends[i])
                {
                    range_ends[i] = true;
                    --todo;
                    if(todo==0)
                    {
                        break;
                    }
                }
            }
        }
        assert(todo==0);
        
        bool first = true;
        for(int i=0; i<n; ++i)
        {
            if(range_ends[i])
            {
                if(first)
                {
                    first = false;
                }
                else
                {
                    cout << " ";
                }
                cout << i+1;
            }
        }
        return 0;
    }
    
    assert(false);
    return 0;
}