#include <bits/stdc++.h> typedef long long ll; typedef long double ld; typedef unsigned long long ull; using namespace std; int n, k; vector<int> a; void solve_k2(){ vector<int> minl(n), maxr(n); minl[0] = a[0]; maxr[n-1] = a[n-1]; for(int i = 1; i < n; i++){ minl[i] = min(minl[i-1], a[i]); } for(int i = n-2; i >= 0; i--){ maxr[i] = max(maxr[i+1], a[i]); } for(int i = 0; i < n-1; i++){ if (minl[i]>=maxr[i+1]){ cout << "TAK\n" << i+1 << "\n"; return; } } cout << "NIE\n"; } void solve_k3(){ int mini = 1e9+7, maxi = -1e9-7; int minpos = -1, maxpos = -1; for(int i = 0; i < n; i++){ if (a[i] <= mini){ mini = a[i]; minpos = i; } if (a[i] > maxi){ maxi = a[i]; maxpos = i; } } if (minpos != 0){ if (minpos == n-1){ cout << "TAK\n" << 1 << " " << minpos << "\n"; return; } cout << "TAK\n" << minpos << " " << minpos+1 << "\n"; return; } if (maxpos != n-1){ if (maxpos == 0){ cout << "TAK\n" << maxpos+1 << " " << 2 << "\n"; return; } cout << "TAK\n" << maxpos << " " << maxpos+1 << "\n"; return; } cout << "NIE\n"; } void solve_k4(){ int cut = -1; for(int i = 0; i < n-1; i++){ if (a[i] >= a[i+1]){ cut = i; break; } } if (cut == -1){ cout << "NIE\n"; return; } vector<int> cuts = {cut+1}; if (cut != 0){ cuts.push_back(cut); } if(cut+2 != n){ cuts.push_back(cut+2); } int idx = 1; while(cuts.size() != k-1){ if(idx != cut && idx != cut+1 && idx != cut+2){ cuts.push_back(idx); } idx++; } sort(cuts.begin(), cuts.end()); cout << "TAK\n"; for(int i = 0; i < cuts.size(); i++){ cout << cuts[i] << " "; } cout << "\n"; } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); cin >> n >> k; a.resize(n); for(int i = 0; i < n; i++){ cin >> a[i]; } if (k==2){ solve_k2(); } else if (k==3){ solve_k3(); } else{ solve_k4(); } }
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 | #include <bits/stdc++.h> typedef long long ll; typedef long double ld; typedef unsigned long long ull; using namespace std; int n, k; vector<int> a; void solve_k2(){ vector<int> minl(n), maxr(n); minl[0] = a[0]; maxr[n-1] = a[n-1]; for(int i = 1; i < n; i++){ minl[i] = min(minl[i-1], a[i]); } for(int i = n-2; i >= 0; i--){ maxr[i] = max(maxr[i+1], a[i]); } for(int i = 0; i < n-1; i++){ if (minl[i]>=maxr[i+1]){ cout << "TAK\n" << i+1 << "\n"; return; } } cout << "NIE\n"; } void solve_k3(){ int mini = 1e9+7, maxi = -1e9-7; int minpos = -1, maxpos = -1; for(int i = 0; i < n; i++){ if (a[i] <= mini){ mini = a[i]; minpos = i; } if (a[i] > maxi){ maxi = a[i]; maxpos = i; } } if (minpos != 0){ if (minpos == n-1){ cout << "TAK\n" << 1 << " " << minpos << "\n"; return; } cout << "TAK\n" << minpos << " " << minpos+1 << "\n"; return; } if (maxpos != n-1){ if (maxpos == 0){ cout << "TAK\n" << maxpos+1 << " " << 2 << "\n"; return; } cout << "TAK\n" << maxpos << " " << maxpos+1 << "\n"; return; } cout << "NIE\n"; } void solve_k4(){ int cut = -1; for(int i = 0; i < n-1; i++){ if (a[i] >= a[i+1]){ cut = i; break; } } if (cut == -1){ cout << "NIE\n"; return; } vector<int> cuts = {cut+1}; if (cut != 0){ cuts.push_back(cut); } if(cut+2 != n){ cuts.push_back(cut+2); } int idx = 1; while(cuts.size() != k-1){ if(idx != cut && idx != cut+1 && idx != cut+2){ cuts.push_back(idx); } idx++; } sort(cuts.begin(), cuts.end()); cout << "TAK\n"; for(int i = 0; i < cuts.size(); i++){ cout << cuts[i] << " "; } cout << "\n"; } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); cin >> n >> k; a.resize(n); for(int i = 0; i < n; i++){ cin >> a[i]; } if (k==2){ solve_k2(); } else if (k==3){ solve_k3(); } else{ solve_k4(); } } |