#include <bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) int n, k, INF = 1e9; vector<int> x; vector<int> solve2(){ vector<int> s(n+1); s[n] = x[n]; for(int i = n-1; i >= 1; i--) s[i] = max(s[i+1], x[i]); int mn = INF; for(int i = 1; i <= n-1; i++){ mn = min(mn, x[i]); if(mn >= s[i+1]) return {i}; } return {}; } vector<int> solve3(){ int mn = INF; for(int i = 1; i <= n-1; i++){ mn = min(mn, x[i]); if(mn >= x[i+1]) return {i, i+1}; } int mx = 0; for(int i = n; i >= 2; i--){ mx = max(mx, x[i]); if(mx <= x[i-1]) return {i-1, i}; } return {}; } vector<int> solve(){ if(k == 2) return solve2(); if(k == 3) return solve3(); vector<bool> vis(n+1); bool ok = false; for(int i = 1; i <= n-1; i++) if(x[i] >= x[i+1] && !ok) vis[i-1] = vis[i] = vis[i+1] = ok = true; if(!ok) return {}; vector<int> res; int s = 3; if(vis[n] == true) vis[n] = false, s--; for(int i = 1; i <= n; i++){ if(vis[i]) res.push_back(i); else if(s < k){ res.push_back(i); s++; } } return res; } int main(){ fastio; cin >> n >> k; x.resize(n+1); for(int i = 1; i <= n; i++) cin >> x[i]; vector<int> res = solve(); if(res.empty()) cout << "NIE"; else{ cout << "TAK\n"; for(int r : res) cout << r << " "; } }
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 | #include <bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) int n, k, INF = 1e9; vector<int> x; vector<int> solve2(){ vector<int> s(n+1); s[n] = x[n]; for(int i = n-1; i >= 1; i--) s[i] = max(s[i+1], x[i]); int mn = INF; for(int i = 1; i <= n-1; i++){ mn = min(mn, x[i]); if(mn >= s[i+1]) return {i}; } return {}; } vector<int> solve3(){ int mn = INF; for(int i = 1; i <= n-1; i++){ mn = min(mn, x[i]); if(mn >= x[i+1]) return {i, i+1}; } int mx = 0; for(int i = n; i >= 2; i--){ mx = max(mx, x[i]); if(mx <= x[i-1]) return {i-1, i}; } return {}; } vector<int> solve(){ if(k == 2) return solve2(); if(k == 3) return solve3(); vector<bool> vis(n+1); bool ok = false; for(int i = 1; i <= n-1; i++) if(x[i] >= x[i+1] && !ok) vis[i-1] = vis[i] = vis[i+1] = ok = true; if(!ok) return {}; vector<int> res; int s = 3; if(vis[n] == true) vis[n] = false, s--; for(int i = 1; i <= n; i++){ if(vis[i]) res.push_back(i); else if(s < k){ res.push_back(i); s++; } } return res; } int main(){ fastio; cin >> n >> k; x.resize(n+1); for(int i = 1; i <= n; i++) cin >> x[i]; vector<int> res = solve(); if(res.empty()) cout << "NIE"; else{ cout << "TAK\n"; for(int r : res) cout << r << " "; } } |