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
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int const N = 5e5 + 9;
int n, k;
int tab[N];
pair<int,int> tab2[N];

int mini[N]; //pref
int maxi[N]; //suf

bool dwa(int n2) {
    sort(tab2 + 1, tab2 + n2+ 1);
    for (int i = n; i >= 1; i--)
        maxi[i] = max(maxi[i + 1], tab[i]);
    for (int i = 1; i <= n; i++)
        mini[i] = min(mini[i - 1], tab[i]);

    for (int i = 1; i < n; i++) {
        if (mini[i] > maxi[i + 1]) {
            cout << "TAK\n";
            cout << i << "\n";
            return true;
        }
    }
    cout << "NIE\n";
    return false;
}

bool odw[N];

void cztery() {
    sort(tab2 + 1, tab2 + n + 1);
    bool pos = false;
    odw[n] = true;
    for (int i = n; i >= 1; i--) {
        if (tab2[i].second != i) {
            pos = true;
            odw[tab2[i].second] = true;
            odw[tab2[i].second - 1] = true;
            odw[i + 1] = true;
        }
    }
    if (pos == false) {
        cout << "NIE\n";
        return;
    }
    int ile = 4, index = 1;
    while (ile < k) {
        if (odw[index] == false) {
            odw[index] = true;
            ile++;
        }
        index++;
    }
    cout << "TAK\n";
    for (int i = 1; i < n; i++) {
        if (odw[i] == true)
            cout << i << " ";
    }
    cout << "\n";
}

void trzy() {
    sort(tab2 + 1, tab2 + n + 1);
    int maxi = tab2[n].first, ile = 0;
    for (int i = n; i >= 1; i--) {
        if (tab2[n].first != maxi) break;
        if (tab2[n].second != i) {
            // to da sie wziac tego
            cout << "TAK\n";
            cout << tab2[n].second - 1 << " " << tab2[n].second << "\n";
            return;
        }
        ile++;
    }
    for (int i = 1; i <= n - ile; i++)
        tab2[i] = { tab[i], i };
    bool odp = dwa(n - ile);
    if (odp == true)
        cout << n - ile << "\n";
}

void solve() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> tab[i];
        tab2[i] = { tab[i], i };
    }
    if (k == 2) dwa(n);
    else if (k == 3) trzy();
    else cztery();
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}