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
#include<cstdio>
#include<algorithm>
#define S 500007

using namespace std;

int T[S];

int minPref[S];
int maxSuf[S];

int ans[S];

int main(void){
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i = 1; i <= n;i++){
        scanf("%d",&T[i]);
    }

    if(k == 2){
        minPref[1] = T[1];
        for(int i = 2; i <= n;i++){
            minPref[i] = min(minPref[i-1],T[i]);
        }

        maxSuf[n] = T[n];
        for(int i = n-1; i >= 1;i--){
            maxSuf[i] = max(maxSuf[i+1],T[i]);
        }

        for(int i = 1; i < n;i++){
            if(minPref[i] >= maxSuf[i+1]){
                printf("TAK\n%d",i);
                return 0;
            }
        }
        printf("NIE");
        return 0;
    }else if(k == 3){
        int mini = 1e9 + 100;
        int lastMini = 0;

        int maxi = -1;
        int firstMaxi = -1;

        for(int i = 1; i <= n;i++){
            if(T[i] <= mini){
                mini = T[i];
                lastMini = i;
            }
            if(T[i] > maxi){
                maxi = T[i];
                firstMaxi = i;
            }
        }

        if(firstMaxi == n && lastMini == 1){
            printf("NIE");
            return 0;
        }

        printf("TAK\n");
        if(firstMaxi != n){
            if(firstMaxi == 1){
                printf("%d %d",1,2);
            }else{
                printf("%d %d",firstMaxi-1,firstMaxi);
            }
            return 0;
        }

        if(lastMini != 1){
            if(lastMini == n){
                printf("%d %d",n-2,n-1);
            }else{
                printf("%d %d",lastMini-1,lastMini);
            }
            return 0;
        }

    }else{
        bool good = false;
        k--;
        for(int i = 1; i < n;i++){
            if(T[i] >= T[i+1]){
                good = true;
                ans[i] = 1;
                k--;
                if(i != 1){
                    ans[i-1] = 1;
                    k--;
                }
                if(i+1 != n){
                    ans[i+1] = 1;
                    k--;
                }
                break;
            }
        }
        if(!good){
            printf("NIE");
            return 0;
        }
        printf("TAK\n");
        for(int i = 1; i < n;i++){
            if(k > 0 && ans[i] == 0){
                ans[i] = 1;
                k--;
            }
            if(ans[i])
                printf("%d ",i);
        }
    }

    return 0;
}