#!/usr/bin/env python3.10 import sys n, k = [int(x) for x in sys.stdin.readline().split(" ")] N = [int(x) for x in sys.stdin.readline().split(" ") if x != "\n"] minS = [N[0]] * n maxE = [N[-1]] * n for i in range(1, n): minS[i] = min(minS[i - 1], N[i]) for i in range(n-2, -1, -1): maxE[i] = max(maxE[i + 1], N[i]) done = False if k == 2: for i in range(1, n): if minS[i - 1] >= maxE[i]: print("TAK") print(i) done = True break elif k == 3: for i in range(1, n - 1): if minS[i - 1] >= N[i] or maxE[i + 1] <= N[i]: print("TAK") print(f"{i} {i + 1}") done = True break else: for i in range(1, n): if N[i - 1] >= N[i]: print("TAK") mustSet = [x for x in [i - 1, i, i + 1] if 0 < x < n] toSet = k - 1 - len(mustSet) before = [] for i in range(1, n): if toSet == 0: break if i < mustSet[0]: toSet -= 1 before.append(i) if i > mustSet[-1]: toSet -= 1 mustSet.append(i) result = [str(x) for x in before] for m in mustSet: result.append(str(m)) print(" ".join(result)) done = True break if not done: print("NIE")
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 | #!/usr/bin/env python3.10 import sys n, k = [int(x) for x in sys.stdin.readline().split(" ")] N = [int(x) for x in sys.stdin.readline().split(" ") if x != "\n"] minS = [N[0]] * n maxE = [N[-1]] * n for i in range(1, n): minS[i] = min(minS[i - 1], N[i]) for i in range(n-2, -1, -1): maxE[i] = max(maxE[i + 1], N[i]) done = False if k == 2: for i in range(1, n): if minS[i - 1] >= maxE[i]: print("TAK") print(i) done = True break elif k == 3: for i in range(1, n - 1): if minS[i - 1] >= N[i] or maxE[i + 1] <= N[i]: print("TAK") print(f"{i} {i + 1}") done = True break else: for i in range(1, n): if N[i - 1] >= N[i]: print("TAK") mustSet = [x for x in [i - 1, i, i + 1] if 0 < x < n] toSet = k - 1 - len(mustSet) before = [] for i in range(1, n): if toSet == 0: break if i < mustSet[0]: toSet -= 1 before.append(i) if i > mustSet[-1]: toSet -= 1 mustSet.append(i) result = [str(x) for x in before] for m in mustSet: result.append(str(m)) print(" ".join(result)) done = True break if not done: print("NIE") |