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
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int a[500'009];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k,mini=0,maks=0,minw=1'000'000'009,maksw=-1;
    cin >> n >> k;
    for (int x=1;x<=n;x++){
        cin >> a[x];
        if (a[x] == minw){
            mini = -1;
        }
        if (a[x] < minw){
            mini = x;
            minw = a[x];
        }
        if (a[x]==maksw){
            maks = -1;
        }
        if (a[x] > maksw){
            maks = x;
            maksw = a[x];
        }
    }
    if (k>=4){
        k -= 1;
        int kon[500'009];
        int flag=0;
        for (int x=1;x<n;x++){
            if (a[x]>=a[x+1]){
                flag = 1;
                if (x>1){
                    kon[x-1] = 1;
                    k -= 1;
                }
                kon[x] = 1;
                k -= 1;
                if (x+1<=n){
                    kon[x+1] = 1;
                    k -= 1;
                }
                break;
            }
        }
        if (flag==0){
            cout << "NIE\n";
            return 0;
        }
        for (int x=1;x<n && k>0;x++){
            if (kon[x] == 0){
                kon[x] = 1;
                k -= 1;
            }
        }
        cout << "TAK\n";
        for (int x=0;x<n;x++){
            if (kon[x] == 1){
                cout << x << ' ';
            }
        }
    }
    else if(k==3){
        int dowmin=1,dowmaks=1;
        for (int x=1;x<=n;x++){
            if (a[x]<=a[dowmin]){
                dowmin = x;
            }
            if (a[x] > a[dowmaks]){
                dowmaks = x;
            }
        }
        if (dowmin!=1){
            if (dowmin == n){
                cout << "TAK\n" << 1 << ' ' << dowmin-1 << '\n';
            }
            else{
                cout << "TAK\n" << dowmin-1 << ' ' << dowmin << '\n';
            }
            return 0;
        }
        if (dowmaks!=n){
            if (dowmaks == 1){
                cout << "TAK\n" << 1 << ' ' << 2 << '\n';
            }
            else{
                cout << "TAK\n" << dowmaks-1 << ' ' << dowmaks << '\n';
            }
            return 0;
        }
        cout << "NIE\n";
    }
    else if(k==2){
        int pmaks[9];
        int pmin[9];
        pmaks[n+1] = 0;
        pmin[0] = 1'000'000'009;
        for (int x=n;x>=1;x--){
            pmaks[x] = max(pmaks[x+1],a[x]);
        }
        for (int x=1;x<=n;x++){
            pmin[x] = min(pmin[x-1],a[x]);
        }
        for (int x=1;x<n;x++){
            if (pmin[x] >= pmaks[x+1]){
                cout << "TAK\n";
                cout << x << '\n';
                return 0;
            }
        }
        cout << "NIE\n";
    }
    return 0;
}