In “can you search” problem I am getting tle in python.Please suggest how to resolve
created
last reply
- 7
replies
- 1.0k
views
- 2
users
- 1
link
In “can you search” problem I am getting tle in python.Please suggest how to resolve
@wisfaq please reply
Problem AGPC01F
Are you searching the array for every query? You could process the array once for each test case, and then answer each query directly.
Here is my code
import sys
T = sys.stdin.readline()
T = int(T)
for t in range(T):
m,n = sys.stdin.readline().split()
m = int(m)
listing = [int(i) for i in sys.stdin.readline().split()]
finding = [int(i) for i in sys.stdin.readline().split()]
for i in range(1,m):
if(listing[i]>listing[i-1]):
listing[i] = listing[i-1]
for number in finding:
print listing[number-1]