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

×

turbo sort TLE

hey i'm getting tle (time limit exceeded) for the following code the problem is http://www.codechef.com/problems/TSORT/

itr = int(raw_input())
arr = []
for i in xrange(0,itr):
    inp = int(raw_input())
    arr.append(inp)
arr.sort()
for i in xrange(0,itr):
    print arr[i]

im not getting the problem in it pls help........

Thanx....

asked 23 Jul '14, 14:53

dpmittal's gravatar image

1★dpmittal
26115
accept rate: 0%


actually this qus requires O(n) sorting algorithm, take a look at the constraints for N, you can use count sort :)

link

answered 23 Jul '14, 17:23

mrolympia's gravatar image

5★mrolympia
-23
accept rate: 0%

-1

The i/p o/p speed of python is not great combined that with you using the sort function with an average time complexity of nlogn. Maybe the nlogn implementation can work in c/c++ with faster i/p & o/p but not in this implementation of python at least. Try reading about counting sort.

Hope that helps :)

link

answered 23 Jul '14, 15:37

chalubhalu's gravatar image

4★chalubhalu
2902411
accept rate: 6%

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:

×214
×113

question asked: 23 Jul '14, 14:53

question was seen: 815 times

last updated: 23 Jul '14, 17:23