#include <bits/stdc++.h>
#define pb push_back
using namespace std;
constexpr int MAXN = 5e5 + 7;
int a[MAXN];
int min_pref[MAXN];
int max_suf[MAXN];
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
int n, k;
cin >> n >> k;
bool rosnacy = true;
for(int i = 1; i <= n; i++) {
cin >> a[i];
if(a[i] <= a[i-1]) rosnacy = false;
}
if(rosnacy) {
cout << "NIE";
}
else {
if(k >= 4) {
int x = -1;
for(int i = 1; i <= n-1; i++) {
if(a[i] >= a[i+1]) {
x = i;
break;
}
}
set<int> ans;
ans.insert(x);
ans.insert(x+1);
if(x > 1) ans.insert(x-1);
for(int i = 1; i <= n; i++) {
if(ans.size() < k-1) ans.insert(i);
if(ans.size() == k-1) break;
}
cout << "TAK\n";
for(auto a: ans) cout << a << ' ';
}
else {
min_pref[0] = 1e9 + 7;
max_suf[n+1] = 0;
for(int i = 1; i <= n; i++) {
min_pref[i] = min(min_pref[i-1], a[i]);
max_suf[n-i+1] = max(max_suf[n-i+2], a[n-i+1]);
}
//for(int i = 1; i <= n; i++) cout << min_pref[i] << ' '; cout << '\n';
//for(int i = 1; i <= n; i++) cout << max_suf[i] << ' '; cout << '\n';
bool git2 = false;
int x = -1;
for(int i = 1; i <= n-1; i++) {
if(min_pref[i] >= max_suf[i+1]) {
git2 = true;
x = i;
break;
}
}
if(k == 2) {
if(!git2) cout << "NIE";
else cout << "TAK\n" << x;
}
else if(k == 3) {
bool git3 = false;
for(int i = n-1; i >= 1; i--) {
if(a[i] >= max_suf[i+1]) {
git3 = true;
cout << "TAK\n";
if(i-1 >= 1) {
cout << i-1 << ' ' << i;
}
else cout << i << ' ' << i+1;
break;
}
}
if(!git3) {
bool git007 = false;
for(int i = 2; i <= n-1; i++) {
if(a[i] <= min_pref[i-1]) {
git007 = true;
cout << "TAK\n" << i-1 << ' ' << i;
break;
}
}
if(!git007) cout << "NIE";
}
}
}
}
return 0;
}
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 | #include <bits/stdc++.h> #define pb push_back using namespace std; constexpr int MAXN = 5e5 + 7; int a[MAXN]; int min_pref[MAXN]; int max_suf[MAXN]; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); int n, k; cin >> n >> k; bool rosnacy = true; for(int i = 1; i <= n; i++) { cin >> a[i]; if(a[i] <= a[i-1]) rosnacy = false; } if(rosnacy) { cout << "NIE"; } else { if(k >= 4) { int x = -1; for(int i = 1; i <= n-1; i++) { if(a[i] >= a[i+1]) { x = i; break; } } set<int> ans; ans.insert(x); ans.insert(x+1); if(x > 1) ans.insert(x-1); for(int i = 1; i <= n; i++) { if(ans.size() < k-1) ans.insert(i); if(ans.size() == k-1) break; } cout << "TAK\n"; for(auto a: ans) cout << a << ' '; } else { min_pref[0] = 1e9 + 7; max_suf[n+1] = 0; for(int i = 1; i <= n; i++) { min_pref[i] = min(min_pref[i-1], a[i]); max_suf[n-i+1] = max(max_suf[n-i+2], a[n-i+1]); } //for(int i = 1; i <= n; i++) cout << min_pref[i] << ' '; cout << '\n'; //for(int i = 1; i <= n; i++) cout << max_suf[i] << ' '; cout << '\n'; bool git2 = false; int x = -1; for(int i = 1; i <= n-1; i++) { if(min_pref[i] >= max_suf[i+1]) { git2 = true; x = i; break; } } if(k == 2) { if(!git2) cout << "NIE"; else cout << "TAK\n" << x; } else if(k == 3) { bool git3 = false; for(int i = n-1; i >= 1; i--) { if(a[i] >= max_suf[i+1]) { git3 = true; cout << "TAK\n"; if(i-1 >= 1) { cout << i-1 << ' ' << i; } else cout << i << ' ' << i+1; break; } } if(!git3) { bool git007 = false; for(int i = 2; i <= n-1; i++) { if(a[i] <= min_pref[i-1]) { git007 = true; cout << "TAK\n" << i-1 << ' ' << i; break; } } if(!git007) cout << "NIE"; } } } } return 0; } |
English