You are not logged in. Please login at www.codechef.com to post your questions!

×

TIME LIMIT EXCEDED PLEASE HELP

https://www.codechef.com/problems/HORSES

i was submitting my code for the question although my code is doing exactly the same which was asked i am getting a time limit exceeded error which i cant figure out as i am new to C.P t=input("enter no of test cases") i=0 while i<t: a="map(eval,raw_input("" ").split())="" print="" a="" l="[]" for="" i="" in="" range(0,len(a)):="" for="" j="" in="" range(0,len(a)):="" if(a[i]="">a[j] and i!=j): c=a[i]-a[j] l.append(c) elif(a[i]<a[j] and i!=j): d=a[j]-a[i] l.append(d) i=i=1 l.sort() print l[0]

this is my code please help

asked 13 Sep, 20:44

abhishek1200's gravatar image

0★abhishek1200
1
accept rate: 0%


You are trying to find all the differences, but you just need the minimum difference. sort() is your friend.

If you solve the time limit issue, you will still get "wrong answer" though, because of all the unrequested output you are generating, including input prompts which are not needed here, and debugging print-out. Be sure to clear all that away before submitting.

link

answered 13 Sep, 20:56

joffan's gravatar image

4★joffan
6967
accept rate: 11%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×913
×611
×121

question asked: 13 Sep, 20:44

question was seen: 38 times

last updated: 13 Sep, 20:56