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
#include <iostream>
using namespace std;
int tab[500009];
int prefixy[500009];
int suffixy[500009];
int cunt, gates;
int highest=0, secondhighest=0;
int main()
{
    cin >> cunt >> gates;

    for (int i = 1; i <= cunt; i++)
    {
        cin >> tab[i];
    }
    int stalerosnacy = 1;
    if (gates >= 4)
    {
        if (tab[1] == tab[2])
        {
            cout << "TAK" << endl;
            cout << 1 << " " << 2;
            for (int i = 3; i < gates; i++)
            {
                cout << i << " ";
            }
            return 0;
        }
        for (int i = 1; i < cunt; i++)
        {
            if (tab[i] >= tab[i + 1])
            {
                stalerosnacy = 0;
                cout << "TAK" << endl;
                for (int j = 1; j < min(gates - 3, i - 1); j++)
                {
                    cout << j << " ";
                }
                cout << i - 1 << " " << i << " " << i + 1 << " ";
                for (int j = i + 2; j < gates; j++)
                {
                    cout << j << " ";
                }
                return 0;
            }
        }
        if (stalerosnacy == 1)
        {
            cout << "NIE";
            return 0;
        }
    }
    int stalenierosnacy = 1;
    if (gates == 2)
    {
        for (int i = 1; i < cunt; i++)
        {
            if (tab[i] < tab[i + 1])
            {
                stalenierosnacy = 0;
            }
        }
        if (stalenierosnacy == 1)
        {
            cout << "TAK" << endl;
            cout << 1;
            return 0;
        }
        else
        {
            cout << "NIE";
            return 0;
        }
    }
    
    if (gates == 3)
    {
        if (tab[1] == tab[2])
        {
            cout << "TAK" << endl;
            cout << 1 <<" "<< 2;
            return 0;
        }
        if (tab[cunt-1] == tab[cunt])
        {
            cout << "TAK" << endl;
            cout << cunt - 2 << " " << cunt - 1;
        }
        prefixy[1] = tab[1];
        for (int i = 2; i <= cunt; i++)
        {
            prefixy[i] = max(tab[i], prefixy[i - 1]);
        }
        suffixy[cunt] = tab[cunt];
        for (int i = cunt; i >= 1; i--)
        {
            suffixy[i] = max(tab[i], suffixy[i + 1]);
        }
        for (int i = 1; i < cunt; i++)
        {
            if (prefixy[i] >= suffixy[i + 1])
            {
                cout << "TAK" << endl;
                cout << i - 1 << " " << i;
                return 0;
            }
        }
        cout << "NIE" << endl;
        return 0;
    }
}