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

#define MAX_N 500010

using namespace std;

int n, k;
int perf[MAX_N];
int prefMin[MAX_N];
int sufMax[MAX_N];
bool writeDown[MAX_N];

void solveLargeK() {
    int index = -1;
    for (int i = 1; i < n; i++) {
        if (perf[i] <= perf[i - 1]) {
            index = i;
            break;
        }
    }
    if (index == -1) {
        printf("NIE\n");
        return;
    }

    int left = k - 1;

    writeDown[index] = true;
    left--;
    if (index + 1 != n) {
        writeDown[index + 1] = true;
        left--;
    }

    printf("TAK\n");
    for (int i = 1; i < n; i++) {
        if (!writeDown[i] && left > 0) {
            writeDown[i] = true;
            left--;
        }
        if (writeDown[i]) printf("%d ", i);
    }
    printf("\n");
}

void solveK3() {
    int maxI = 0;
    int minI = 0;
    for (int i = 1; i < n; i++) {
        if (perf[i] > perf[maxI]) {
            maxI = i;
        }
        if (perf[i] <= perf[minI]) {
            minI = i;
        }
    }

    if (maxI != n - 1) {
        //printf("TAK\n");
        printf("TAK\n%d %d\n", maxI, maxI + 1);
        return;
    } else if (minI != 0) {
        //printf("TAK\n");
        printf("TAK\n%d %d\n", minI, minI + 1);       
        return;
    } else {
        printf("NIE\n");
        return;
    }
}

void solveK2() {
    prefMin[0] = perf[0];
    for (int i = 1; i < n; i++) {
        prefMin[i] = min(prefMin[i - 1], perf[i]);
    }
    sufMax[n - 1] = perf[n - 1];
    for (int i = n - 2; i >= 0; i--) {
        sufMax[i] = max(sufMax[i + 1], perf[i]);
    }
    for (int i = 1; i < n; i++) {
        if (prefMin[i - 1] >= sufMax[i]) {
            //printf("TAK\n");
            printf("TAK\n%d\n", i);
            return;
        }
    }
    printf("NIE\n");
    return;
}

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%d", &perf[i]);
    }
    
    if (k == 1) {
        printf("NIE\n");
    } else if (k == 2) {
        solveK2();
    } else if (k == 3) {
        solveK3();
    } else {
        solveLargeK();
    }
}