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
#include <iostream>
#include <climits>
#include <array>
#include <set>

using std::cin, std::cout;

//!!! 500'007
const int MAX_N = 500'007;
const char endl = '\n';

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, parts;
    cin >> n >> parts;

    std::array<int, MAX_N> maxBefore;
    std::array<int, MAX_N> inputNums;

    int prevmin = INT_MAX;
    int min = INT_MAX;
    int max = -INT_MAX;
    int minindex, maxindex;
    for (int i = 1; i <= n; i++)
    {
        int num; cin >> num;
        inputNums[i]=num;
        if (num >= max)
        {
            max = num;
            maxindex = i;
        }
        if (num <= min)
        {
            min = num;
            minindex = i;
        }
        maxBefore[i] = maxindex;
    }

    int cutoffIndex = n;
    int leftSurIndex;
    int rightSurIndex;
    while (true)
    {
        if (maxBefore[cutoffIndex] == cutoffIndex)
        {
            cutoffIndex--;
        }
        else
        {
                        //finish
            leftSurIndex = maxBefore[cutoffIndex]-1;
            rightSurIndex = maxBefore[cutoffIndex];
            if (cutoffIndex == minindex) //last == min
            {
                leftSurIndex = minindex-1;
                rightSurIndex = minindex;
            }
            
            break;
        }
    }

    if (leftSurIndex < 1 || leftSurIndex >= n) leftSurIndex = -1;
    if (rightSurIndex < 1 || rightSurIndex >= n) rightSurIndex = -1;
    if (cutoffIndex < 1 || cutoffIndex >= n) cutoffIndex = -1;
    std::set<int> splitIndices = {-1, leftSurIndex, rightSurIndex, cutoffIndex};

    int unusedSplits = parts - splitIndices.size();
    if (splitIndices.size() <= parts)
    {
        cout << "TAK" << endl;
        //fill unused splits
        for (int i = 1; i < n; i++)
        {
            if (splitIndices.count(i) == 1)
            {
                cout << i << ' ';
            }
            else if (unusedSplits > 0)
            {
                unusedSplits--;
                cout << i << ' ';
            }
        }
        
    }
    else
    {
        cout << "NIE";
    }
    return 0;
}