TSORT: Whenever I try to run this code on my PC, it says TSORT.exe has stopped working. What is wrong with it??

alt text

Your array size is too large to be declared inside main.
Declaring it globally would solve the problem.

1 Like

Thank you! It did work!
Why didn’t I face this problem in other questions? Here, almost every array has size of this order.

Also, this is giving TLE. Is merge sort the only option to do this problem?

No it is better to do using Quick sort

using printf and scanf .cin cout are slow .

in other problems… it must have been of the order 10^5.
i dont know the exact size limit …but i checked on my pc and 510^5 is permissible but 610^5 is not.
Also the inbuilt sort function you used is faster than your merge sort.as suggested either you can use fast IO or (possibly why this problem was set) using counting sort(Counting sort - Wikipedia).The concept behind
it is very easy to understand and very useful in some problems.

regarding tsort i think you will still have to use fast IO

while any comparision sort runs in O(Nlog(N)), counting sort runs in O(M+N) where M is the upper bound on your integer elements.

@allthepeopleabove Here’s the link to my answer:
http://www.codechef.com/viewsolution/3968457

I have already used faster I/O, made the sync with stdio false so there should not be any problem with cout, right?
I’m trying this comparison sort btw. @shubham12 thanks!