from sys import stdin, stdout def complete_solution(partial_solution, k, n): partial_solution = [x for x in partial_solution if 0<x<n] i = k-len(partial_solution) solution = set(range(1, i)) solution.update(partial_solution) while len(solution) < k-1: solution.add(i) i += 1 return list(solution) def find_solution_for_2(income, n): prefix_min = income.copy() minimum = income[0] for i in range(n): minimum = min(minimum, income[i]) prefix_min[i] = minimum sufix_max = income.copy() maximum = income[n-1] for i in range(n-1, -1, -1): maximum = max(maximum, income[i]) sufix_max[i] = maximum for i in range(n-1): if prefix_min[i]>=sufix_max[i+1]: return [i+1] return [] def find_solution_for_3(income, n): min_arg = 0 for i in range(1, n): if income[i] <= income[min_arg]: min_arg = i if min_arg>0: return [min_arg, min_arg+1] max_arg = n - 1 for i in range(n-1, -1, -1): if income[i] >= income[max_arg]: max_arg = i if max_arg<n-1: return [max_arg, min_arg+1] return [] def find_solution_for_4(income, n): for i in range(1, n): if income[i-1] >= income[i]: partial_solution = [i-1, i, i+1] return partial_solution return [] n, k = [int(x) for x in stdin.readline().split()] income = [int(x) for x in stdin.readline().split()] if k==2: partial_solution = find_solution_for_2(income, n) elif k==3: partial_solution = find_solution_for_3(income, n) else: partial_solution = find_solution_for_4(income, n) if len(partial_solution)==0: stdout.write("NIE\n") else: stdout.write("TAK\n") solution = complete_solution(partial_solution, k, n) stdout.write(" ".join([str(x) for x in solution])+"\n")
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 | from sys import stdin, stdout def complete_solution(partial_solution, k, n): partial_solution = [x for x in partial_solution if 0<x<n] i = k-len(partial_solution) solution = set(range(1, i)) solution.update(partial_solution) while len(solution) < k-1: solution.add(i) i += 1 return list(solution) def find_solution_for_2(income, n): prefix_min = income.copy() minimum = income[0] for i in range(n): minimum = min(minimum, income[i]) prefix_min[i] = minimum sufix_max = income.copy() maximum = income[n-1] for i in range(n-1, -1, -1): maximum = max(maximum, income[i]) sufix_max[i] = maximum for i in range(n-1): if prefix_min[i]>=sufix_max[i+1]: return [i+1] return [] def find_solution_for_3(income, n): min_arg = 0 for i in range(1, n): if income[i] <= income[min_arg]: min_arg = i if min_arg>0: return [min_arg, min_arg+1] max_arg = n - 1 for i in range(n-1, -1, -1): if income[i] >= income[max_arg]: max_arg = i if max_arg<n-1: return [max_arg, min_arg+1] return [] def find_solution_for_4(income, n): for i in range(1, n): if income[i-1] >= income[i]: partial_solution = [i-1, i, i+1] return partial_solution return [] n, k = [int(x) for x in stdin.readline().split()] income = [int(x) for x in stdin.readline().split()] if k==2: partial_solution = find_solution_for_2(income, n) elif k==3: partial_solution = find_solution_for_3(income, n) else: partial_solution = find_solution_for_4(income, n) if len(partial_solution)==0: stdout.write("NIE\n") else: stdout.write("TAK\n") solution = complete_solution(partial_solution, k, n) stdout.write(" ".join([str(x) for x in solution])+"\n") |