For COOK82C, I have coded the same C++ code (which got AC) in python, still getting TLE. As pointed out by @harsha_man in (TLE in python 3) have replaced all input() with stdin.readline().
You can find the code snippet below:
from sys import *
n, m = [int(i) for i in stdin.readline().split()]
A = [int(i) for i in stdin.readline().split()]
query = []
for _ in range(m):
query.append(int(stdin.readline()))
A.sort(reverse = True)
q = []
ans = None
ct = 1
i = 0
while ct <= query[m-1]:
if len(q)==0:
ans = A.pop(0)
elif len(A)==0:
ans = q.pop(0)
else:
if A[0] > q[0]:
ans = A.pop(0)
else:
ans = q.pop(0)
if ans//2 > 0:
q.append(ans//2)
if ct == query[i]:
stdout.write(str(ans) + '\n')
i += 1
ct+=1