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

using namespace std;

const int MAXN = 500000;

int a[MAXN+5];
int maxr[MAXN+5];

#define PRINTSOL
//#undef PRINTSOL

int main() {
    int n, k = 0;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i) {
        scanf("%d", a+i);
    }
    if (k >= 4) {
        int wyswietlone = 0;
        for (int i = 1; i < n; ++i) {
            if (a[i-1]>= a[i]) {
                printf("TAK\n");
                int minus = (!(i == 1 || i==n-1)) ? 4 : 3;
                for (int j=0; wyswietlone < k - minus && j < i-2; ++j) {
#ifdef PRINTSOL
                    printf("%d ", j+1);
#endif
                    ++wyswietlone;
                }
                if (i == 1) {
                    #ifdef PRINTSOL
                    printf("%d %d ", i, i+1);
#endif
                    wyswietlone += 2;
                } else if (i==n-1) {
                    #ifdef PRINTSOL
                    printf("%d %d ", i-1, i);
#endif
                    wyswietlone += 2;
                } else {
#ifdef PRINTSOL
                    printf("%d %d %d ", i-1, i, i+1);
#endif
                    wyswietlone += 3;
                }
                for (int j = i+1; j < n-1 && wyswietlone < k-1; ++j){
#ifdef PRINTSOL
                    printf("%d ", j+1);
#endif
                    ++wyswietlone;
                }
                //assert(wyswietlone == k-1);
                return 0;
            }
        }
        printf("NIE\n");
    } else if (k == 3) {
        for (int i = 1; i < n; ++i) {
            if (a[i] <= a[0]) {
                printf("TAK\n");
#ifdef PRINTSOL
                if (i != n-1) {
                    printf("%d %d ", i, i+1);
                } else {
                    printf("%d %d ", 1, n-1);
                }
#endif
                return 0;
            }
        }
        for (int i = n-2; i >= 0; --i) {
            if (a[i] >= a[n-1]) {
                printf("TAK\n");
#ifdef PRINTSOL
                if (i != 0) {
                    printf("%d %d ", i, i+1);
                } else {
                    printf("%d %d ", 1, n-1);
                }
#endif
                return 0;
            }
        }
        printf("NIE\n");
    } else { // 2
        maxr[n-1] = a[n-1];
        for (int i = n-2; i >= 0; --i) {
            maxr[i] = max(maxr[i+1], a[i]);
        }
        int minl = a[0];
        for (int i = 1; i < n; ++i) {
            if (minl >= maxr[i]) {
                printf("TAK\n");
#ifdef PRINTSOL
                printf("%d ", i);
#endif
                return 0;
            }
            minl = min(minl, a[i]);
        }
        printf("NIE\n");
    }
}