Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def bin_search(s, e, l, x):
- if e >= s:
- mid = s+(e-s)//2
- if l[mid] == x:
- return mid
- elif l[mid] > x:
- return bin_search(s, mid-1, l, x)
- elif l[mid] < x:
- return bin_search(mid+1, e, l, x)
- else:
- return -1
- def bin_s(s, e, l, x):
- if e >= s:
- mid = s+(e-s)//2
- if l[mid][0] <= x and l[mid][m-1] >= x:
- return mid
- elif l[mid][0] > x:
- return bin_s(s, mid-1, l, x)
- elif l[mid][m-1] < x:
- return bin_s(mid+1, e, l, x)
- else:
- return -1
- def find(n, m, t, x):
- px, py = -1, -1
- if t[0][0] > x or t[n-1][m-1] < x:
- return -1, -1
- else:
- px = bin_s(0, n-1, t, x)
- if px != -1:
- py = bin_search(0, m-1, t[px], x)
- return px, py
- if __name__ == "__main__":
- n = int(input())
- m = int(input())
- t = []
- for i in range(n):
- p = []
- for j in range(m):
- x = int(input())
- p.append(x)
- t.append(p)
- x = int(input())
- a, b = find(n, m, t, x)
- if a == -1 or b == -1:
- print("Not found")
- else:
- print("["+str(a)+", "+str(b)+"]")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement