#include <iostream> #include <set> int n, k; using namespace std; int tab[500002]; int min_range[500002]; int min_val = 1e9+1, min_idx; int max_val, max_idx; int not_rising = 0; int split_k_2; using namespace std; int main() { cin >> n >> k; min_range[0] = 1e9+1; for (int i = 1; i <= n; i++) { cin >> tab[i]; if (tab[i] <= tab[i-1]) { not_rising = i; } if (tab[i] <= min_val) { min_val = tab[i]; min_idx = i; } min_range[i] = min(min_range[i-1], tab[i]); } for (int i = n; i >= 1; i--) { if (tab[i] >= max_val) { max_val = tab[i]; max_idx = i; } if (i > 1) { if (max_val <= min_range[i-1]) { split_k_2 = i-1; } } } if (k == 2) { if (split_k_2 == 0) { cout << "NIE" << endl; } else { cout << "TAK" << endl; cout << split_k_2 << endl; } } if (k == 3) { if (min_idx == 1 && max_idx == n) { cout << "NIE" << endl; } else { cout << "TAK" << endl; if (min_idx == n) { min_idx--; } if (max_idx == 1) { max_idx++; } if (min_idx != 1) { cout << min_idx - 1 << " " << min_idx << endl; } else { cout << max_idx - 1 << " " << max_idx << endl; } } } if (k >= 4) { if (not_rising == 0) { cout << "NIE" << endl; } else { cout << "TAK" << endl; if (not_rising == n) { not_rising = n-1; } else if (not_rising == 2) { not_rising = 3; } int start = max(1, not_rising - k + 2); for (int i = start; i < start + k - 1; 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 | #include <iostream> #include <set> int n, k; using namespace std; int tab[500002]; int min_range[500002]; int min_val = 1e9+1, min_idx; int max_val, max_idx; int not_rising = 0; int split_k_2; using namespace std; int main() { cin >> n >> k; min_range[0] = 1e9+1; for (int i = 1; i <= n; i++) { cin >> tab[i]; if (tab[i] <= tab[i-1]) { not_rising = i; } if (tab[i] <= min_val) { min_val = tab[i]; min_idx = i; } min_range[i] = min(min_range[i-1], tab[i]); } for (int i = n; i >= 1; i--) { if (tab[i] >= max_val) { max_val = tab[i]; max_idx = i; } if (i > 1) { if (max_val <= min_range[i-1]) { split_k_2 = i-1; } } } if (k == 2) { if (split_k_2 == 0) { cout << "NIE" << endl; } else { cout << "TAK" << endl; cout << split_k_2 << endl; } } if (k == 3) { if (min_idx == 1 && max_idx == n) { cout << "NIE" << endl; } else { cout << "TAK" << endl; if (min_idx == n) { min_idx--; } if (max_idx == 1) { max_idx++; } if (min_idx != 1) { cout << min_idx - 1 << " " << min_idx << endl; } else { cout << max_idx - 1 << " " << max_idx << endl; } } } if (k >= 4) { if (not_rising == 0) { cout << "NIE" << endl; } else { cout << "TAK" << endl; if (not_rising == n) { not_rising = n-1; } else if (not_rising == 2) { not_rising = 3; } int start = max(1, not_rising - k + 2); for (int i = start; i < start + k - 1; i++) { cout << i << " "; } cout << endl; } } return 0; } |