//Franciszek Witt #include<bits/stdc++.h> using namespace std; #define FOR(i,l,r) for(int i=(l);i<=(r);++i) #define REP(i,n) FOR(i,0,(n)-1) #define ssize(x) int(x.size()) template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';} template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';} #ifdef DEBUG #define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n' #else #define debug(...) {} #endif typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<int> v(n); for(auto &i : v) cin >> i; auto mnp = v, mxs = v; for(int i = 1; i < n; i++) mnp[i] = min(mnp[i], mnp[i - 1]); for(int i = n - 2; i >= 0; --i) mxs[i] = max(mxs[i], mxs[i + 1]); vector<int> en(n); bool ok = 0; if(k == 2) { for(int i = 0; i < n - 1; i++) { if(mnp[i] >= mxs[i + 1]) { ok = 1; en[i] = 1; break; } } } else if(k == 3) { for(int i = 0; i < n - 2; i++) { if(mnp[i] >= v[i + 1] || v[i + 1] >= mxs[i + 2]) { ok = 1; en[i] = 1; en[i + 1] = 1; break; } } } else { for(int i = 0; i < n - 1; i++) { if(v[i] >= v[i + 1]) { if(i) en[i - 1] = 1; en[i] = 1; en[i + 1] = 1; ok = 1; break; } } } if(en[n - 1]) en[n - 1] = 0; int il = k - 1 - accumulate(en.begin(), en.end(), 0); for(int i = 0; i < n; i++) { if(il && !en[i]) { en[i] = 1; --il; } } vector<int> ou; for(int i = 0; i < n; i++) if(en[i]) ou.emplace_back(i + 1); if(!ok) cout << "NIE" << endl; else { cout << "TAK" << endl; if(ssize(ou) != k - 1) cout << "-1" << endl; for(auto i : ou) cout << i << " "; cout << endl; } }
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 | //Franciszek Witt #include<bits/stdc++.h> using namespace std; #define FOR(i,l,r) for(int i=(l);i<=(r);++i) #define REP(i,n) FOR(i,0,(n)-1) #define ssize(x) int(x.size()) template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';} template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';} #ifdef DEBUG #define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n' #else #define debug(...) {} #endif typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<int> v(n); for(auto &i : v) cin >> i; auto mnp = v, mxs = v; for(int i = 1; i < n; i++) mnp[i] = min(mnp[i], mnp[i - 1]); for(int i = n - 2; i >= 0; --i) mxs[i] = max(mxs[i], mxs[i + 1]); vector<int> en(n); bool ok = 0; if(k == 2) { for(int i = 0; i < n - 1; i++) { if(mnp[i] >= mxs[i + 1]) { ok = 1; en[i] = 1; break; } } } else if(k == 3) { for(int i = 0; i < n - 2; i++) { if(mnp[i] >= v[i + 1] || v[i + 1] >= mxs[i + 2]) { ok = 1; en[i] = 1; en[i + 1] = 1; break; } } } else { for(int i = 0; i < n - 1; i++) { if(v[i] >= v[i + 1]) { if(i) en[i - 1] = 1; en[i] = 1; en[i + 1] = 1; ok = 1; break; } } } if(en[n - 1]) en[n - 1] = 0; int il = k - 1 - accumulate(en.begin(), en.end(), 0); for(int i = 0; i < n; i++) { if(il && !en[i]) { en[i] = 1; --il; } } vector<int> ou; for(int i = 0; i < n; i++) if(en[i]) ou.emplace_back(i + 1); if(!ok) cout << "NIE" << endl; else { cout << "TAK" << endl; if(ssize(ou) != k - 1) cout << "-1" << endl; for(auto i : ou) cout << i << " "; cout << endl; } } |