#include <iostream> #include <algorithm> #include <vector> using namespace std; std::vector<int> v; int n,k; void solve1() { int i = 1; for (;i<n;i++) if (v[i-1] >= v[i]) break; if (i == n) { std::cout << "NIE\n"; return; } std::cout << "TAK\n"; k--; if (i==n-1) { k-=2; for (int q=1;q<=k;q++) std::cout << q << ' '; std::cout << i-1 << ' ' << i << std::endl; return; } if (i==1) { for (int q=1;q<=k;q++) cout << q << ' '; std::cout << std::endl; return; } k-=3; for (int q=1;q<i-1 && k>0; q++, k--) std::cout << q << ' '; std::cout << i-1 << ' '<< i << ' ' << i+1 << ' '; for (int q=i+2;k>0;q++,k--) std::cout << q << ' ' ; std::cout << std::endl; } void solve2() { std::vector<int> mi,mx; mi.resize(n); mx.resize(n); mi[0] = v[0]; int tmp = mi[0]; for (int i=1;i<n;i++) { if (v[i] < tmp) tmp = v[i]; mi[i] = tmp; } mx[n-1] = v[n-1]; tmp = v[n-1]; for (int i=n-2;i>=0;i--) { if (v[i] > tmp) tmp = v[i]; mx[i] = tmp; } for (int i=1;i<n;i++) { if (mi[i-1] >= mx[i]) { std::cout << "TAK\n" << i << std::endl; return; } } std::cout << "NIE\n"; } void solve3() { int mi = v[0]; for (int i=1;i<n;i++) { if (v[i] <= mi) { std::cout << "TAK\n" << i << ' ' << i+1 << std::endl; return; } } int mx = v[n-1]; for (int i=n-2;i>=0;i--) { if (v[i] >= mx) { std::cout << "TAK\n" << i << ' ' << i+1 << std::endl; return; } } std::cout << "NIE\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; v.resize(n); for (int i=0;i<n;i++) cin >> v[i]; if (k>3) solve1(); else if (k==2) solve2(); else if (k==3) solve3(); }
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 | #include <iostream> #include <algorithm> #include <vector> using namespace std; std::vector<int> v; int n,k; void solve1() { int i = 1; for (;i<n;i++) if (v[i-1] >= v[i]) break; if (i == n) { std::cout << "NIE\n"; return; } std::cout << "TAK\n"; k--; if (i==n-1) { k-=2; for (int q=1;q<=k;q++) std::cout << q << ' '; std::cout << i-1 << ' ' << i << std::endl; return; } if (i==1) { for (int q=1;q<=k;q++) cout << q << ' '; std::cout << std::endl; return; } k-=3; for (int q=1;q<i-1 && k>0; q++, k--) std::cout << q << ' '; std::cout << i-1 << ' '<< i << ' ' << i+1 << ' '; for (int q=i+2;k>0;q++,k--) std::cout << q << ' ' ; std::cout << std::endl; } void solve2() { std::vector<int> mi,mx; mi.resize(n); mx.resize(n); mi[0] = v[0]; int tmp = mi[0]; for (int i=1;i<n;i++) { if (v[i] < tmp) tmp = v[i]; mi[i] = tmp; } mx[n-1] = v[n-1]; tmp = v[n-1]; for (int i=n-2;i>=0;i--) { if (v[i] > tmp) tmp = v[i]; mx[i] = tmp; } for (int i=1;i<n;i++) { if (mi[i-1] >= mx[i]) { std::cout << "TAK\n" << i << std::endl; return; } } std::cout << "NIE\n"; } void solve3() { int mi = v[0]; for (int i=1;i<n;i++) { if (v[i] <= mi) { std::cout << "TAK\n" << i << ' ' << i+1 << std::endl; return; } } int mx = v[n-1]; for (int i=n-2;i>=0;i--) { if (v[i] >= mx) { std::cout << "TAK\n" << i << ' ' << i+1 << std::endl; return; } } std::cout << "NIE\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; v.resize(n); for (int i=0;i<n;i++) cin >> v[i]; if (k>3) solve1(); else if (k==2) solve2(); else if (k==3) solve3(); } |