MERGSORT - Mergesort

Simple. Sort the numbers on the standard input using the merge sort algorithm. Don't try to cheat by just calling your build in functions... I can see your source.

Input

On the standard input you will receive N (1 <= N <= 100000). Each number will fit in 32-bit integer

Output

Output the same integers in a sorted manner. Smallest to largest.

Example

Input:
7 3 2 5 4 3

Output:
2 3 3 4 5 7

Added by:Nikola P Borisov
Date:2008-11-17
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET

hide comments
2013-11-18 04:48:07 Andi
Nevermind, how u said, u get it in the string.

Last edit: 2013-11-18 05:07:08
2013-04-25 12:28:06 Ouditchya Sinha
@bansal, use
i = 0 ;
while( scanf("%d",&n) != EOF ) { a[i++] = n ; }
2012-09-04 19:46:58 Breno
you have to receive the numbers into a string
2012-08-28 20:30:17 bansal
how will i know how many numbers are there ?????
2012-06-04 23:48:52 Felipe Lima [UFS]
Anurag, the input is finished with end of file
2011-03-14 03:19:06 Anurag Atri
how will i know how many numbers are there ?Or how can i know the end of input .
2009-09-23 17:23:27 যোবায়ের
Number of inversions can also be counted by quicksort, but a bit tedious.
A problem can be mentioned at UVA OJ, 10810, ULTRA QUICK SORT
2009-03-08 18:49:33 David Pìgøímek (Davpe)
I think, this problem is really good, finally something, that forces me to program MergeSort ;). But it should be in tutorial, so no one could bother cheating.
2009-11-03 13:49:41 .:: Pratik ::.
why is SPOJ going down these days?
2009-03-02 21:35:19 Brian Bi
How about counting the number of inversions in the sequence? It's doable with mergesort but not any other sort (I think), and is an intrinsic property of the sequence, whereas the left/right switch count seems a bit... ad hoc. For example, given the sequence 3 1 2, the number of switches depends on whether you split it as 3 | 1 2 or 3 1 | 2.

Last edit: 2009-03-02 21:35:19
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.