RKS - RK Sorting
RK is a great code breaker. He knows any cipher in the world can be broken by frequency analysis. He intercepted an enemy message. The message consists of N numbers, smaller than or equal to C. RK belives freqency analysis consists of sorting this sequence so that more frequent numbers appear before less frequent ones.
Formally, the sequence must be sorted so that given any two numbers X and Y , X appears before Y if the number of times X appears in the original sequence is larger than the number of time Y does. If the number of appearances is equal, the number whoes value appears sooner in the input should appear sooner in the sorted sequence.
Help RK by creating a "frequency sorter".
Input
First line of input contains two integers, N (1 <= N <= 1000), length of message, and C (1 <= C <= 10^9), the number from task description. Next line contains N integers smaller than or equal to C, message itself.
Output
First and only line of output should contain N numbers, the sorted sequence.
Sample
Input 9 3 1 3 3 3 2 2 2 1 1 Output 1 1 1 3 3 3 2 2 2
Input 5 2 2 1 2 1 2 Output 2 2 2 1 1
hide comments
deadbrain:
2016-06-18 11:52:25
Cakewalk for those familiar with STL. Try doing it in C. Learnt structure sorting using qsort. |
|
arun_1997:
2016-06-10 10:07:26
really good question of stl..
|
|
Siddharth Singh:
2016-03-26 09:30:46
It Was A Hell Of A Question <3 |
|
PRIYANSHU SAINI:
2015-08-25 12:58:11
excellent use of stl... AC in one go
|
|
Amit Ajaat:
2015-06-07 11:12:02
Don't dare to do with C language-ITS totally a question to introduce you to map standard templates.....in C merge sort on structures may work.......something is going wrong in testcase 10 with C language...learned new concepts of C++ standard templates...finally accepted.GOOOOOOOOD QUESTion... |
|
:.Mohib.::
2015-05-31 19:43:56
Nice que..!! Again cpp rocks..!! |
|
AKASH GOEL:
2014-12-30 15:15:22
very nice problem..
|
|
Archangel:
2014-12-11 14:30:13
very nice application of STL in this problem! |
|
vimal:
2014-12-04 09:01:29
learnt new complex things... :D(i donno why c code crashed after 10TC inspite of using long long and all those shits..) |
|
Pawankumar P:
2014-12-02 16:06:50
Half century on spoj. |
Added by: | BLANKRK |
Date: | 2014-01-28 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |