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
#include <bits/stdc++.h>
using namespace std;
int T[500001];
int mi[500001];
int ma[500001];
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    for (int i = 1; i <= n;i++){
        scanf("%d",&T[i]);
    }
    if (k == 2){
        mi[1] = T[1];
        for (int i = 2; i <= n;i++){
            mi[i] = min(T[i],mi[i-1]);
        }
        ma[n] = T[n];
        for (int i = n - 1; i >= 1;i--){
            ma[i] = max(ma[i+1],T[i]);
        }
        int tak = 0;
        for (int i = 1; i <= n- 1;i++){
            if (tak == 0){
                if (mi[i] >= ma[i+1]){
                    tak = i;
                }
            }
        }
        if (tak == 0){
            printf("NIE");
        }
        else{
            printf("TAK \n");
            printf("%d",tak);
        }
    }
    if (k == 3){
        int max_id = 1;
        int min_id = 1;
        int min_w = T[1];
        int max_w = T[1];
        for (int i = 2;i <= n;i++){
            if (T[i] <= min_w){
                min_w = T[i];
                min_id = i;
            }
            if (T[i] > max_w){
                max_w = T[i];
                max_id = i;
            }
        }
        if (min_id == 1 && max_id == n){
            printf("NIE");
        }
        else{
            if (min_id != 1){
                if (min_id == n){
                    printf("TAK \n");
                    printf("1 %d",n-1);
                }
                else{
                    printf("TAK \n");
                    printf("%d %d",min_id - 1, min_id);
                }
            }
            else{//min_id == 1, max_id != n
                if (max_id == 1){
                    printf("TAK \n");
                    printf("1 2");
                }
                else{
                    printf("TAK \n");
                    printf("%d %d",max_id - 1, max_id);
                }
            }
        }
    }
    if (k >= 4){
        int tak = 0;
        for (int i = 2; i <= n;i++){
            if (tak == 0 && T[i] <= T[i-1]){
                tak = i;
            }
        }
        if (tak == 0){
            printf("NIE");
        }
        else{
            printf("TAK \n");
            if (tak < k){
                for (int i = 1; i < k;i++){
                    printf("%d ",i);
                }
            }
            else{
                for (int i = 1; i < k - 3;i++){
                    printf("%d ",i);
                }
                printf("%d %d %d",tak-2,tak-1,tak);
            }
        }
    }
}