8 / 8
Jan 2018

In “can you search” problem I am getting tle in python.Please suggest how to resolve

  • created

    Dec '17
  • last reply

    Jan '18
  • 7

    replies

  • 1.0k

    views

  • 2

    users

  • 1

    link

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.

11 days later

My suggestions are:

  1. find out under what conditions, and where in the code the runtime error occurs,
  2. adjust the code to stop it happening.

This process is known as “debugging” and it’s a skill that will come in very useful :wink:

Failing that, post the code that has the problem.

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]

I can’t say I tested it exhaustively, but it seems to work OK for me. Do you still get RE?