#include <bits/stdc++.h> #define ll long long #define fors(u, n, s) for(ll u=(s); u < (n); u++) #define foru(u, n) fors(u, n, 0) #define ir(a, b, x) (((a) <= (x)) && ((x) <= (b))) #define vec vector #define pb push_back using namespace std; #define N 500010 int arr[N]; int min_pre[N]; int max_suf[N]; bool ans[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; int k; cin >> n >> k; foru(i, n) cin >> arr[i]; min_pre[0]=arr[0]; fors(i, n, 1) min_pre[i]=min(min_pre[i-1], arr[i]); max_suf[n-1]=arr[n-1]; for(int i=n-2; i>=0; i--) max_suf[i]=max(max_suf[i+1], arr[i]); foru(i, n) ans[i]=false; if(k==2){ foru(i, n-1){ if(min_pre[i]>=max_suf[i+1]){ cout << "TAK" << endl << i+1; return 0; } } cout << "NIE"; return 0; } if(k==3){ if(arr[0]>=arr[n-1]){ cout << "TAK" << endl << 1 << " " << n-1; return 0; } fors(i, n-1, 1){ if(arr[i]<=min_pre[i-1] || arr[i]>=max_suf[i+1]){ cout << "TAK" << endl << i << " " << i+1 << endl; return 0; } } cout << "NIE" << endl; return 0; } foru(i, n-1){ if(arr[i]>=arr[i+1]){ k--; if(i!=0){ ans[i-1]=true; k--; } ans[i]=true; k--; if(i!=n-1){ ans[i+1]=true; k--; } foru(i, n){ if(k==0) break; if(!ans[i]) {ans[i]=true; k--;} } cout << "TAK" << endl; foru(i, n) if(ans[i]) cout << i+1 << " "; return 0; } } 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 | #include <bits/stdc++.h> #define ll long long #define fors(u, n, s) for(ll u=(s); u < (n); u++) #define foru(u, n) fors(u, n, 0) #define ir(a, b, x) (((a) <= (x)) && ((x) <= (b))) #define vec vector #define pb push_back using namespace std; #define N 500010 int arr[N]; int min_pre[N]; int max_suf[N]; bool ans[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; int k; cin >> n >> k; foru(i, n) cin >> arr[i]; min_pre[0]=arr[0]; fors(i, n, 1) min_pre[i]=min(min_pre[i-1], arr[i]); max_suf[n-1]=arr[n-1]; for(int i=n-2; i>=0; i--) max_suf[i]=max(max_suf[i+1], arr[i]); foru(i, n) ans[i]=false; if(k==2){ foru(i, n-1){ if(min_pre[i]>=max_suf[i+1]){ cout << "TAK" << endl << i+1; return 0; } } cout << "NIE"; return 0; } if(k==3){ if(arr[0]>=arr[n-1]){ cout << "TAK" << endl << 1 << " " << n-1; return 0; } fors(i, n-1, 1){ if(arr[i]<=min_pre[i-1] || arr[i]>=max_suf[i+1]){ cout << "TAK" << endl << i << " " << i+1 << endl; return 0; } } cout << "NIE" << endl; return 0; } foru(i, n-1){ if(arr[i]>=arr[i+1]){ k--; if(i!=0){ ans[i-1]=true; k--; } ans[i]=true; k--; if(i!=n-1){ ans[i+1]=true; k--; } foru(i, n){ if(k==0) break; if(!ans[i]) {ans[i]=true; k--;} } cout << "TAK" << endl; foru(i, n) if(ans[i]) cout << i+1 << " "; return 0; } } cout << "NIE"; return 0; } |