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>
using namespace std;
int min_left[500005];
int max_right[500005];
int t[500005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k, i;
    cin >> n >> k;
    min_left[0] = 2000000000;
    bool growing = true;
    for (i = 1; i <= n; i++)
    {
        cin >> t[i];
        if (t[i] < min_left[i-1]) min_left[i] = t[i];
        else min_left[i] = min_left[i-1];
        if (t[i] <= t[i-1]) growing = false;
    }
    if (growing) cout << "NIE";
    else{
        for (i = n; i >= 1; i--)
        {
            if (t[i] > max_right[i+1]) max_right[i] = t[i];
            else max_right[i] = max_right[i+1];
        }
        if (k == 2){
            int ans = 0;
            for (i = 1; i < n; i++)
            {
                if (min_left[i] >= max_right[i+1]){
                    ans = i;
                    //cout << min_left[i] << "  " << max_right[i+1];
                    break;
                }
            }
            if (ans == 0) cout << "NIE";
            else cout << "TAK\n" << ans;
        }
        else if (k == 3){
            int ans = 0;
            for (i = 1; i < n; i++)
            {
                if (t[i] >= max_right[i+1]){
                    ans = i; 
                    if (i == 1) ans = 2;
                    break;
                }
                //cout << i << " " << t[i] << " " << max_right[i+1] << "\n";
            }
            if (ans == 0){
                for(i = 2; i <= n; i++)
                {
                    if (t[i] <= min_left[i-1]){
                        ans = i;
                        if (i == n) ans = n-1;
                        break;
                    }
                }
            }
            if (ans == 0) cout << "NIE";
            else {
                cout << "TAK\n" << ans-1 << " " << ans;
            }
        }
        else{
            int ans = 0;
            for (int i = 1; i < n; i++)
            {
                if (t[i] >= t[i+1]){
                    ans = i;
                    if (i == 1) ans = 2;
                    if (i == n-1) ans = n-2;
                    break;
                }
            }
            if (ans == 0) cout << "NIE";
            else{
                int counter = k-4;
                //if (ans == n-1) counter = k-3;
                cout << "TAK\n";
                for (i = 1; i <= n; i++)
                {
                    if (i == ans-1 || i == ans || i == ans+1) cout << i << " ";
                    else if (counter > 0){
                        cout << i << " ";
                        counter--;
                    }
                }
            }
        }

    }
        return 0;
}