#include <iostream> using namespace std; int t[500010],m1[500010]; bool res[500010]; int main(){ ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,k; cin >> n >> k; if(k == 3){ int mini = 1e9 + 10; for(int i = 0; i < n; i++){ cin >> t[i]; if(i < n - 1 && i > 0){ if(mini >= t[i]){ cout << "TAK\n" << i << " " << i + 1<< "\n"; return 0; } }mini = min(t[i],mini); }mini = t[n-1]; for(int i = n - 2; i >= 1; i--){ if(t[i] >= mini){ cout << "TAK\n" << i << " " << i + 1 << "\n"; return 0; } mini = max(mini,t[i]); } cout << "NIE\n"; } else if(k == 2){ for(int i = 0; i < n; i++){ m1[i] = 1e9 + 10; cin >> t[i]; m1[i] = min(m1[max(0,i-1)],t[i]); }int maxx = t[n-1]; for(int i = n-2; i >= 0; i--){ if(m1[i] >= maxx){ cout << "TAK\n" << i + 1 << "\n"; return 0; } maxx = max(t[i],maxx); }cout << "NIE\n"; }else{ int ans = -1; for(int i = 0; i < n; i++){ cin >> t[i]; if(i && t[i] <= t[i-1]){ if(i==1)k -= 3; else if(i==n-1)k -= 3; else k -= 4; res[max(i-2,0)] = res[i-1] = res[i] = 1; ans = i; break; } } if(ans == -1){ cout << "NIE\n"; return 0; } cout << "TAK\n"; for(int i = 0; i < n-1; i++){ if(k && !res[i]){ k--; cout << i + 1 << " "; } if(res[i]){ cout << i + 1 << " "; } } } }
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 | #include <iostream> using namespace std; int t[500010],m1[500010]; bool res[500010]; int main(){ ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,k; cin >> n >> k; if(k == 3){ int mini = 1e9 + 10; for(int i = 0; i < n; i++){ cin >> t[i]; if(i < n - 1 && i > 0){ if(mini >= t[i]){ cout << "TAK\n" << i << " " << i + 1<< "\n"; return 0; } }mini = min(t[i],mini); }mini = t[n-1]; for(int i = n - 2; i >= 1; i--){ if(t[i] >= mini){ cout << "TAK\n" << i << " " << i + 1 << "\n"; return 0; } mini = max(mini,t[i]); } cout << "NIE\n"; } else if(k == 2){ for(int i = 0; i < n; i++){ m1[i] = 1e9 + 10; cin >> t[i]; m1[i] = min(m1[max(0,i-1)],t[i]); }int maxx = t[n-1]; for(int i = n-2; i >= 0; i--){ if(m1[i] >= maxx){ cout << "TAK\n" << i + 1 << "\n"; return 0; } maxx = max(t[i],maxx); }cout << "NIE\n"; }else{ int ans = -1; for(int i = 0; i < n; i++){ cin >> t[i]; if(i && t[i] <= t[i-1]){ if(i==1)k -= 3; else if(i==n-1)k -= 3; else k -= 4; res[max(i-2,0)] = res[i-1] = res[i] = 1; ans = i; break; } } if(ans == -1){ cout << "NIE\n"; return 0; } cout << "TAK\n"; for(int i = 0; i < n-1; i++){ if(k && !res[i]){ k--; cout << i + 1 << " "; } if(res[i]){ cout << i + 1 << " "; } } } } |