#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back typedef pair <int, int> pii; typedef long long ll; typedef double db; const int N = 5e5; const int INF = 1e9 + 1; int n, k, id, cnt; bool t; int a[N + 5], mn[N + 5], mx[N + 5]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> k >> a[0]; mn[0] = a[0]; for(int i=1; i<n; i++){ cin >> a[i]; mn[i] = min(mn[i - 1], a[i]); } mx[n - 1] = a[n - 1]; mx[n] = INF; for(int i=n-2; i>=0; i--){ mx[i] = max(mx[i + 1], a[i]); } if(k == 2){ for(int i=0; i<n; i++){ if(mn[i] >= mx[i + 1]){ cout << "TAK\n" << i + 1; return 0; } } cout << "NIE\n"; return 0; } if(k == 3){ for(int i=0; i<n; i++){ if(a[i] == mn[i]){ id = i; } } if(id > 0){ id -= (id == n - 1); cout << "TAK\n" << id << " " << id + 1 << "\n"; return 0; } for(int i=n-1; i>=0; i--){ if(a[i] == mx[i]){ id = i; } } if(id < n - 1){ id += (id == 0); cout << "TAK\n" << id << " " << id + 1 << "\n"; return 0; } cout << "NIE\n"; return 0; } for(int i=1; i<n; i++){ if(a[i - 1] >= a[i]){ t = true; id = i - 1; } } if(t){ cout << "TAK\n"; for(int i=1; i<id; i++){ if(cnt <= k - 4){ cout << i + 1 << " "; cnt ++; } } cout << id << " " << id + 1 << " "; for(int i=id+1; i<n; i++){ if(cnt <= k - 4){ cout << i + 1 << " "; cnt ++; } } }else{ cout << "NIE\n"; } 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 | #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back typedef pair <int, int> pii; typedef long long ll; typedef double db; const int N = 5e5; const int INF = 1e9 + 1; int n, k, id, cnt; bool t; int a[N + 5], mn[N + 5], mx[N + 5]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> k >> a[0]; mn[0] = a[0]; for(int i=1; i<n; i++){ cin >> a[i]; mn[i] = min(mn[i - 1], a[i]); } mx[n - 1] = a[n - 1]; mx[n] = INF; for(int i=n-2; i>=0; i--){ mx[i] = max(mx[i + 1], a[i]); } if(k == 2){ for(int i=0; i<n; i++){ if(mn[i] >= mx[i + 1]){ cout << "TAK\n" << i + 1; return 0; } } cout << "NIE\n"; return 0; } if(k == 3){ for(int i=0; i<n; i++){ if(a[i] == mn[i]){ id = i; } } if(id > 0){ id -= (id == n - 1); cout << "TAK\n" << id << " " << id + 1 << "\n"; return 0; } for(int i=n-1; i>=0; i--){ if(a[i] == mx[i]){ id = i; } } if(id < n - 1){ id += (id == 0); cout << "TAK\n" << id << " " << id + 1 << "\n"; return 0; } cout << "NIE\n"; return 0; } for(int i=1; i<n; i++){ if(a[i - 1] >= a[i]){ t = true; id = i - 1; } } if(t){ cout << "TAK\n"; for(int i=1; i<id; i++){ if(cnt <= k - 4){ cout << i + 1 << " "; cnt ++; } } cout << id << " " << id + 1 << " "; for(int i=id+1; i<n; i++){ if(cnt <= k - 4){ cout << i + 1 << " "; cnt ++; } } }else{ cout << "NIE\n"; } return 0; } |