Problem B
Zipf's Song

At first, you figure that the most listened to songs must be the best songs. However, you quickly realize that this approach is flawed. Even if all songs of the album are equally good, the early songs are more likely to be listened to more often than the later ones, because monkeys will tend to start listening to the first song, listen for a few songs and then, when their fickle ears start craving something else, stop listening. Instead, if all songs are equal, you expect that their play frequencies should follow Zipf’s Law.
Zipf’s Law is an empirical law originally formulated about
word frequencies in natural languages, but it has been observed
that many natural phenomena, such as population sizes and
incomes, approximately follow the same law. It predicts that
the relative frequency of the
To illustrate this in our setting, suppose we have an album
where all songs are equally good. Then by Zipf’s Law, you
expect that the first song is listened to twice as often as the
second song, and more generally that the first song is listened
to
Input
The first line of input contains two integers
Output
Output a list of the
Sample Input 1 | Sample Output 1 |
---|---|
4 2 30 one 30 two 15 three 25 four |
four two |
Sample Input 2 | Sample Output 2 |
---|---|
15 3 197812 re_hash 78906 5_4 189518 tomorrow_comes_today 39453 new_genious 210492 clint_eastwood 26302 man_research 22544 punk 19727 sound_check 17535 double_bass 18782 rock_the_house 198189 19_2000 13151 latin_simone 12139 starshine 11272 slow_country 10521 m1_a1 |
19_2000 clint_eastwood tomorrow_comes_today |