#include "bits/stdc++.h" // Ignacy Boehlke using namespace std; // XIII LO Szczecin template<class A,class B>ostream&operator<<(ostream&os,pair<A,B>p){return os<<'{'<<p.first<<", "<<p.second<<'}';} template<class T>auto operator<<(ostream&os,T v)->decltype(v.end(),os){os<<'{';int i=0;for(auto e:v)os<<(", ")+2*!i++<<e;return os<<'}';} #ifdef DEBUG #define LOG(x...)cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...)<<'\n';}(x) #else #define LOG(...)(void)0 #endif #define ssize(x)((int)x.size()) #define FOR(a,b,c)for(int a=(b);a<=(c);a++) #define REP(a,b)FOR(a,0,(b)-1) #define ALL(x)(x).begin(), (x).end() #define fi first #define se second using ll=long long; void yes(const vector<int>& vec) { cout << "TAK\n"; #ifndef TEST for (int e : vec) cout << e << ' '; cout << '\n'; #endif exit(0); } void no() { cout << "NIE\n"; exit(0); } int main() { cin.tie(0)->sync_with_stdio(0); int n, k; cin >> n >> k; vector<int> c(n + 1); FOR(i, 1, n) cin >> c[i]; if (k <= 3) { vector<int> mxsuf(n + 2), mnpre(n + 1, INT_MAX); for (int i = n; i >= 1; i--) mxsuf[i] = max(mxsuf[i + 1], c[i]); FOR(i, 1, n) mnpre[i] = min(mnpre[i - 1], c[i]); if (k == 2) { FOR(i, 1, n - 1) if (mnpre[i] >= mxsuf[i + 1]) yes({i}); } else { //k == 3 LOG(mnpre); FOR(i, 2, n - 1) if (mnpre[i - 1] >= c[i] || mxsuf[i + 1] <= c[i]) yes({i - 1, i}); } no(); } FOR(i, 2, n) { if (c[i - 1] >= c[i]) { vector<int> res; k -= 4; for (int j = 1; k && j < i - 1; j++, k--) res.push_back(j); res.push_back(i - 1); res.push_back(i); res.push_back(i + 1); for (int j = i + 2; k && j < n; j++, k--) res.push_back(j); yes(res); } } no(); }
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 | #include "bits/stdc++.h" // Ignacy Boehlke using namespace std; // XIII LO Szczecin template<class A,class B>ostream&operator<<(ostream&os,pair<A,B>p){return os<<'{'<<p.first<<", "<<p.second<<'}';} template<class T>auto operator<<(ostream&os,T v)->decltype(v.end(),os){os<<'{';int i=0;for(auto e:v)os<<(", ")+2*!i++<<e;return os<<'}';} #ifdef DEBUG #define LOG(x...)cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...)<<'\n';}(x) #else #define LOG(...)(void)0 #endif #define ssize(x)((int)x.size()) #define FOR(a,b,c)for(int a=(b);a<=(c);a++) #define REP(a,b)FOR(a,0,(b)-1) #define ALL(x)(x).begin(), (x).end() #define fi first #define se second using ll=long long; void yes(const vector<int>& vec) { cout << "TAK\n"; #ifndef TEST for (int e : vec) cout << e << ' '; cout << '\n'; #endif exit(0); } void no() { cout << "NIE\n"; exit(0); } int main() { cin.tie(0)->sync_with_stdio(0); int n, k; cin >> n >> k; vector<int> c(n + 1); FOR(i, 1, n) cin >> c[i]; if (k <= 3) { vector<int> mxsuf(n + 2), mnpre(n + 1, INT_MAX); for (int i = n; i >= 1; i--) mxsuf[i] = max(mxsuf[i + 1], c[i]); FOR(i, 1, n) mnpre[i] = min(mnpre[i - 1], c[i]); if (k == 2) { FOR(i, 1, n - 1) if (mnpre[i] >= mxsuf[i + 1]) yes({i}); } else { //k == 3 LOG(mnpre); FOR(i, 2, n - 1) if (mnpre[i - 1] >= c[i] || mxsuf[i + 1] <= c[i]) yes({i - 1, i}); } no(); } FOR(i, 2, n) { if (c[i - 1] >= c[i]) { vector<int> res; k -= 4; for (int j = 1; k && j < i - 1; j++, k--) res.push_back(j); res.push_back(i - 1); res.push_back(i); res.push_back(i + 1); for (int j = i + 2; k && j < n; j++, k--) res.push_back(j); yes(res); } } no(); } |