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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <iostream>
#include <climits>
#include <cmath>

using namespace std;

void printSequence(int start, int end)
{
    cout << start;
    for (int i = start + 1; i <= end; ++i)
    {
        cout << " " << i;
    }
    cout << endl;
}

void checkIfSequenceIsGrowing(int *data, int n, int k)
{
    for (int i = 1; i < n; ++i)
    {
        if (data[i] <= data[i - 1])
        {
            // mozna podzielic
            cout << "TAK" << endl;
            if (i < k - 1)
            {
                printSequence(1, k - 1);
                return;
            }
            if (i == n - 1)
            {
                printSequence(i + 2 - k, n - 1);
                return;
            }

            printSequence(i + 3 - k, i + 1);
            return;
        }
    }
    cout << "NIE" << endl;
}

void checkExactMinMax(int *data, int n)
{
    // k = 3

    int last_min = INT32_MAX, first_max = -1;
    int last_min_idx = -1, first_max_idx = -1;

    for (int i = 0; i < n; ++i)
    {
        if (data[i] <= last_min)
        {
            last_min = data[i];
            last_min_idx = i;
        }
        if (data[i] > first_max)
        {
            first_max = data[i];
            first_max_idx = i;
        }
    }

    if (last_min_idx != 0)
    {
        cout << "TAK" << endl;
        if (last_min_idx != n - 1)
        {
            cout << last_min_idx << " " << last_min_idx + 1 << endl;
            return;
        }

        cout << n - 2 << " " << n - 1 << endl;
        return;
    }

    if (first_max_idx != n - 1)
    {
        cout << "TAK" << endl;
        if (first_max_idx != 0)
        {
            cout << first_max_idx << " " << first_max_idx + 1 << endl;
            return;
        }

        cout << 1 << " " << 2 << endl;
        return;
    }

    cout << "NIE" << endl;
}

void checkSplitSequence(int *data, int n)
{
    // k = 2
    int *max_suffix = new int[n];

    max_suffix[n - 1] = data[n - 1];
    for (int i = n - 2; i >= 0; --i)
    {
        max_suffix[i] = max(max_suffix[i + 1], data[i]);
    }

    int min_prefix = data[0];
    for (int i = 1; i < n; ++i)
    {
        if (min_prefix >= max_suffix[i])
        {
            cout << "TAK" << endl
                 << i << endl;
            delete[] max_suffix;
            return;
        }
        min_prefix = min(min_prefix, data[i]);
    }
    cout << "NIE" << endl;

    delete[] max_suffix;
}

int main()
{
    int n, k;
    cin >> n >> k;

    int *data = new int[n];
    for (int i = 0; i < n; ++i)
    {
        cin >> data[i];
    }

    if (k >= 4)
    {
        checkIfSequenceIsGrowing(data, n, k);
    }
    else if (k == 3)
    {
        checkExactMinMax(data, n);
    }
    else
    {
        checkSplitSequence(data, n);
    }

    delete[] data;
    return 0;
}