#include <bits/stdc++.h> using namespace std; int arr[500005]; int min_pref[500005]; int max_suf[500005]; bool ans[500005]; bool is_increasing(int n){ for(int i=1;i<n;i++){ if(arr[i] >= arr[i+1]) return false; } return true; } int main(){ ios_base::sync_with_stdio(0); int n, k; cin>>n>>k; for(int i=1;i<=n;i++) cin>>arr[i]; min_pref[0] = 1e9+7; for(int i=1;i<=n;i++) min_pref[i] = min(min_pref[i-1], arr[i]); for(int i=n;i>0;i--) max_suf[i] = max(max_suf[i+1], arr[i]); if(is_increasing(n)) return cout<<"NIE"<<endl, 0; if(k == 2){ for(int i=1;i<n;i++){ if(min_pref[i] >= max_suf[i+1]){ cout<<"TAK"<<endl; cout<<i<<endl; return 0; } } return cout<<"NIE"<<endl, 0; } else if(k == 3){ int min_val = min_pref[n]; int max_val = max_suf[1]; int min_pos, max_pos; for(int i=1;i<=n;i++){ if(arr[i] == min_val) min_pos = i; } for(int i=n;i>0;i--){ if(arr[i] == max_val) max_pos = i; } if(min_pos != 1){ cout<<"TAK"<<endl; if(min_pos == n) cout<<n-2<<" "<<n-1<<endl; else cout<<min_pos-1<<" "<<min_pos<<endl; return 0; } if(max_pos != n){ cout<<"TAK"<<endl; if(max_pos == 1) cout<<1<<" "<<2<<endl; else cout<<max_pos-1<<" "<<max_pos<<endl; return 0; } for(int i=2;i<n;i++){ if(arr[i] == min_val || arr[i] == max_val){ cout<<"TAK"<<endl; cout<<i-1<<" "<<i<<endl; return 0; } } return cout<<"NIE"<<endl, 0; } else{ for(int i=1;i<n;i++){ if(arr[i] >= arr[i+1]){ ans[i-1] = true; ans[i] = true; ans[i+1] = true; break; } } int cnt = k-1; for(int i=1;i<n;i++) if(ans[i]) cnt--; for(int i=1;i<n;i++){ if(cnt > 0 && !ans[i]) cnt--, ans[i] = true; } cout<<"TAK"<<endl; for(int i=1;i<n;i++) if(ans[i]) cout<<i<<" "; cout<<endl; 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 | #include <bits/stdc++.h> using namespace std; int arr[500005]; int min_pref[500005]; int max_suf[500005]; bool ans[500005]; bool is_increasing(int n){ for(int i=1;i<n;i++){ if(arr[i] >= arr[i+1]) return false; } return true; } int main(){ ios_base::sync_with_stdio(0); int n, k; cin>>n>>k; for(int i=1;i<=n;i++) cin>>arr[i]; min_pref[0] = 1e9+7; for(int i=1;i<=n;i++) min_pref[i] = min(min_pref[i-1], arr[i]); for(int i=n;i>0;i--) max_suf[i] = max(max_suf[i+1], arr[i]); if(is_increasing(n)) return cout<<"NIE"<<endl, 0; if(k == 2){ for(int i=1;i<n;i++){ if(min_pref[i] >= max_suf[i+1]){ cout<<"TAK"<<endl; cout<<i<<endl; return 0; } } return cout<<"NIE"<<endl, 0; } else if(k == 3){ int min_val = min_pref[n]; int max_val = max_suf[1]; int min_pos, max_pos; for(int i=1;i<=n;i++){ if(arr[i] == min_val) min_pos = i; } for(int i=n;i>0;i--){ if(arr[i] == max_val) max_pos = i; } if(min_pos != 1){ cout<<"TAK"<<endl; if(min_pos == n) cout<<n-2<<" "<<n-1<<endl; else cout<<min_pos-1<<" "<<min_pos<<endl; return 0; } if(max_pos != n){ cout<<"TAK"<<endl; if(max_pos == 1) cout<<1<<" "<<2<<endl; else cout<<max_pos-1<<" "<<max_pos<<endl; return 0; } for(int i=2;i<n;i++){ if(arr[i] == min_val || arr[i] == max_val){ cout<<"TAK"<<endl; cout<<i-1<<" "<<i<<endl; return 0; } } return cout<<"NIE"<<endl, 0; } else{ for(int i=1;i<n;i++){ if(arr[i] >= arr[i+1]){ ans[i-1] = true; ans[i] = true; ans[i+1] = true; break; } } int cnt = k-1; for(int i=1;i<n;i++) if(ans[i]) cnt--; for(int i=1;i<n;i++){ if(cnt > 0 && !ans[i]) cnt--, ans[i] = true; } cout<<"TAK"<<endl; for(int i=1;i<n;i++) if(ans[i]) cout<<i<<" "; cout<<endl; return 0; } } |