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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <iostream>
#include <list>
using namespace std;

int main(){
    // Jakub Wasilewski (nazwa konta rekrer)
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    int numsAmount;
    int regions;
    cin >> numsAmount;
    cin >> regions;
    int nums[numsAmount+1];
    for(int i = 1; i <= numsAmount; i++){
        cin >> nums[i];
    }
    /*int smallestNumIndex = 1; //smallest, if are few of same value that are all smallest, we pick right one
    int biggestNumIndex = 1; //biggest, if are few of same value that are all biggest, we pick left one
    for(int i = 1; i <= numsAmount; i++){
        if(nums[i] > nums[biggestNumIndex]){
            biggestNumIndex = i;
        }
    }
    for(int i = 1; i <= numsAmount; i++){
        if(nums[i] > nums[biggestNumIndex]){
            smallestNumIndex = i;
        }
    }*/
    if(regions > 3){
        //int biggestNumYetIndex = 1;
        //int numBig = biggestNumYetIndex;
        //int numSmall;
        //for(int i = 2; i <= numsAmount; i++){
        //    if(nums[i] > nums[biggestNumIndex]){
        //        biggestNumIndex = i;
        //    }else{
        //        numBig = biggestNumYetIndex;
        //        numSmall = i;
        //    }
        //}
        //int numAt = 1;
        //for(int i = 1; i <= regions-2;){
        //    if(numAt==numSmall||numAt==numBig){}
        //}
        int regEnd = -1;
        for(int i = 2; i <= numsAmount; i++){
            if(nums[i]>nums[i-1]){
                continue;
            }else{
                regEnd = i;
            }
        }
        if(regEnd == -1){
            cout << "NIE";
        }
        int olR = regions;
        regions -= 4;
        int ind = 1;
        list<int> regs;
        bool r_2 = false;
        bool r_1 = false;
        bool r = false;
        bool numR = false;
        while(regions > 0){
            if(ind == regEnd-2){
                r_2 = true;
            }else if(ind == regEnd-1){
                r_1 = true;
            }else if(ind == regEnd){
                r = true;
            }else if(ind == numsAmount){
                numR = true;
                regions -=1;
                //wont happen
            }else{
                regions -=1;
            }
            regs.push_back(ind);
            ind+=1;
        }
        if(!r_2){
            regs.push_back(regEnd-2);
        }
        if(!r_1){
            regs.push_back(regEnd-1);
        }
        if(!r){
            regs.push_back(regEnd);
        }
        if(!numR){
            regs.push_back(numsAmount);
        }
        cout << "TAK" << "\n";
        for(int i = 1; i <= olR; i++){
            cout << regs.front() << " ";
            regs.pop_front();
        }
    }else if(regions == 2){
        //3333373894897487892222 2
        //3 121212123333
        //47  12

        //759839 34343434 1432
        int region1End = 1;
        int region2Start = numsAmount;
        int region1MinNum = nums[1];
        int region2MaxNum = nums[numsAmount];
        while(region1End < region2Start-1  && region1MinNum > region2MaxNum){
            for(int i = numsAmount; i > region1End; i--){
                if(nums[i]>region1MinNum){
                    for(int j = region1End+1; j <= i; j++){
                        if(region1MinNum > nums[j]){
                            region1MinNum = nums[j];
                        }
                    }
                    region1End = i;
                }
            }
            for(int i = 1; i < region2Start; i++){
                if(nums[i]<region2MaxNum){
                    for(int j = region2Start-1; j >= i; j--){
                        if(region2MaxNum < nums[j]){
                            region2MaxNum = nums[j];
                        }
                    }
                    region2Start = i;
                }
            }
        }
        if(region1End >= region2Start-1  || region1MinNum < region2MaxNum){
            cout << "NIE";
        }else{
            for(int i = numsAmount; i > region1End; i--){
                if(nums[i]>region1MinNum){
                    for(int j = region1End+1; j <= i; j++){
                        if(region1MinNum > nums[j]){
                            region1MinNum = nums[j];
                        }
                    }
                    region1End = i;
                }
            }
            for(int i = 1; i < region2Start; i++){
                if(nums[i]<region2MaxNum){
                    for(int j = region2Start-1; j >= i; j--){
                        if(region2MaxNum < nums[j]){
                            region2MaxNum = nums[j];
                        }
                    }
                    region2Start = i;
                }
            }
            if(region1End >= region2Start-1  || region1MinNum < region2MaxNum){
                cout << "NIE";
            }else{
                cout << "TAK" << "\n";
                cout << region1End;
            }
        }
    }else if(regions == 3){
        int foundNumber = -1;
        for(int i = 2; i <= numsAmount-1; i++){
            if(nums[i]>nums[1]&&nums[i]<nums[numsAmount]){
                continue;
            }else{
                foundNumber = i;
                break;
            }
        }
        if(foundNumber == -1){
            cout << "NIE";
        }else{
            cout << "TAK" << "\n";
            cout << foundNumber-1 << " ";
            cout << foundNumber;
        }
    }else{
        cout << "bruh moment (regions < 2)";
    }
    return 0;
}