def check2(n, profit_list): prefix_mins = [profit_list[0]] for profit in profit_list[1:]: prefix_mins.append(min(profit, prefix_mins[-1])) suffix_max = [profit_list[-1]] for profit in profit_list[-1::-1]: suffix_max.append(max(profit, suffix_max[-1])) suffix_max.reverse() for i in range(n - 1): if prefix_mins[i] >= suffix_max[i + 1]: return [i + 1] return None def check3(n, profit_list): maximum = max(profit_list) max_index = profit_list.index(maximum) if max_index == n - 1: minimum = min(profit_list) last_minimum_index = n - 1 - profit_list[::-1].index(minimum) if last_minimum_index == 0: return None else: return [last_minimum_index, last_minimum_index + 1] elif max_index == 0: return [1, 2] else: return [max_index, max_index + 1] def fill(seq, target_len): if target_len - 3 < seq[0]: return list(range(1, target_len-2)) + seq else: return list(range(1, seq[0])) + seq + list(range(seq[-1] + 1, target_len + 1)) def check4(n, profit_list, k): decrease_index = None for i, x in enumerate(profit_list[:-1]): if x >= profit_list[i+1]: decrease_index = i break if decrease_index is None: return None else: if decrease_index == 0: splitIndex = [1, 2, 3] elif decrease_index == n-2: splitIndex= [n-3, n-2, n-1] else: splitIndex = [decrease_index, decrease_index + 1, decrease_index + 2] return fill(splitIndex, k-1) list_len, k = map(int, input().strip().split(" ")) profits = list(map(int, input().strip().split(" "))) if k == 2: res = check2(list_len, profits) elif k == 3: res = check3(list_len, profits) else: res = check4(list_len, profits, k) if res is None: print('NIE') else: print('TAK') for x in res: print(x, end=' ') print()
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 | def check2(n, profit_list): prefix_mins = [profit_list[0]] for profit in profit_list[1:]: prefix_mins.append(min(profit, prefix_mins[-1])) suffix_max = [profit_list[-1]] for profit in profit_list[-1::-1]: suffix_max.append(max(profit, suffix_max[-1])) suffix_max.reverse() for i in range(n - 1): if prefix_mins[i] >= suffix_max[i + 1]: return [i + 1] return None def check3(n, profit_list): maximum = max(profit_list) max_index = profit_list.index(maximum) if max_index == n - 1: minimum = min(profit_list) last_minimum_index = n - 1 - profit_list[::-1].index(minimum) if last_minimum_index == 0: return None else: return [last_minimum_index, last_minimum_index + 1] elif max_index == 0: return [1, 2] else: return [max_index, max_index + 1] def fill(seq, target_len): if target_len - 3 < seq[0]: return list(range(1, target_len-2)) + seq else: return list(range(1, seq[0])) + seq + list(range(seq[-1] + 1, target_len + 1)) def check4(n, profit_list, k): decrease_index = None for i, x in enumerate(profit_list[:-1]): if x >= profit_list[i+1]: decrease_index = i break if decrease_index is None: return None else: if decrease_index == 0: splitIndex = [1, 2, 3] elif decrease_index == n-2: splitIndex= [n-3, n-2, n-1] else: splitIndex = [decrease_index, decrease_index + 1, decrease_index + 2] return fill(splitIndex, k-1) list_len, k = map(int, input().strip().split(" ")) profits = list(map(int, input().strip().split(" "))) if k == 2: res = check2(list_len, profits) elif k == 3: res = check3(list_len, profits) else: res = check4(list_len, profits, k) if res is None: print('NIE') else: print('TAK') for x in res: print(x, end=' ') print() |