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

const int MAX_LENGTH = 524288;

int length;
int partitions;
int seq[MAX_LENGTH];
int min[MAX_LENGTH];
int max[MAX_LENGTH];
bool ascending = true;
int descent;

int main(void)
{
    scanf("%d %d", &length, &partitions);
    for(int l = 0; l < length; ++l)
    {
        scanf("%d", &seq[l]);
        max[l] = seq[l];
        min[l] = seq[l];
        if(l && min[l - 1] < min[l])
            min[l] = min[l - 1];

        if(l && seq[l] <= seq[l - 1])
        {
            ascending = false;
            descent = l;
        }
    }

    if(ascending)
    {
        puts("NIE");
        return 0;
    }

    if(partitions >= 4)
    {
        puts("TAK");
        for(int p = std::max(1, descent + 1 - partitions + (descent < length)); partitions > 1; ++p, --partitions)
            printf("%d ", p);

        puts("");
        return 0;
    }

    for(int l = length - 2; l >= 0; --l)
        max[l] = std::max(max[l], max[l + 1]);

    // 3
    if(partitions == 3)
        for(int l = 0; l < length - 2; ++l)
            if(min[l] >= seq[l + 1] || seq[l + 1] >= max[l + 2])
            {
                printf("TAK\n%d %d\n", l + 1, l + 2);
                return 0;
            }

    // 2
    for(int l = 0; l < length - 1; ++l)
        if(min[l] >= max[l + 1])
        {
            printf("TAK\n%d\n", l + 1);
            return 0;
        }

    puts("NIE");
    return 0;
}