import io import os input=(io.BytesIO(os.read(0, os.fstat(0).st_size)).readline) n, k = map(int,input().split()) a = list(map(int,input().split())) if k==2: d = [a[0]]+[0]*(n-1) for i in range(1,n): d[i] = min(d[i-1],a[i]) g = [0]*(n-1)+[a[-1]] for i in range(n-2,-1,-1): g[i] = max(g[i+1],a[i]) for i in range(0,n-1): if d[i]>=g[i+1]: print("TAK") print(i+1) break else: print("NIE") elif k==3: md,mdi = a[0],0 for i in range(1,n): if a[i]<=md: md = a[i] mdi = i g = [0]*(n-1)+[a[-1]] mg,mgi = a[n-1],n-1 for i in range(n-2,-1,-1): if a[i] >= mg: mg = a[i] mgi = i if mdi>0 and mdi<n-1: print("TAK") print(mdi,mdi+1) elif mgi>0 and mgi<n-1: print("TAK") print(mgi,mgi+1) elif mdi==0: print("NIE") else: print("TAK") print(1,n-1) else: #k>3 d = [] for i in range(n-1): if a[i]>=a[i+1]: if i>0: d.append(i) d.append(i+1) d.append(i+2) p = 1 while len(d)<k-1 and p<d[0]: d.append(p) p+=1 p = i+3 while len(d)<k-1: d.append(p) p+=1 print("TAK") print(*sorted(d)) break else: 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 61 62 63 64 65 66 67 68 69 70 | import io import os input=(io.BytesIO(os.read(0, os.fstat(0).st_size)).readline) n, k = map(int,input().split()) a = list(map(int,input().split())) if k==2: d = [a[0]]+[0]*(n-1) for i in range(1,n): d[i] = min(d[i-1],a[i]) g = [0]*(n-1)+[a[-1]] for i in range(n-2,-1,-1): g[i] = max(g[i+1],a[i]) for i in range(0,n-1): if d[i]>=g[i+1]: print("TAK") print(i+1) break else: print("NIE") elif k==3: md,mdi = a[0],0 for i in range(1,n): if a[i]<=md: md = a[i] mdi = i g = [0]*(n-1)+[a[-1]] mg,mgi = a[n-1],n-1 for i in range(n-2,-1,-1): if a[i] >= mg: mg = a[i] mgi = i if mdi>0 and mdi<n-1: print("TAK") print(mdi,mdi+1) elif mgi>0 and mgi<n-1: print("TAK") print(mgi,mgi+1) elif mdi==0: print("NIE") else: print("TAK") print(1,n-1) else: #k>3 d = [] for i in range(n-1): if a[i]>=a[i+1]: if i>0: d.append(i) d.append(i+1) d.append(i+2) p = 1 while len(d)<k-1 and p<d[0]: d.append(p) p+=1 p = i+3 while len(d)<k-1: d.append(p) p+=1 print("TAK") print(*sorted(d)) break else: print("NIE") |