Last active
December 19, 2015 08:58
-
-
Save marconi/5929095 to your computer and use it in GitHub Desktop.
A slightly faster zipfsong implementation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from heapq import heappush, heappop | |
def run(): | |
album_songs_count, songs_count = raw_input().split() | |
album_songs_count = int(album_songs_count) + 1 | |
songs_count = int(songs_count) | |
songs = [] | |
for i in xrange(1, album_songs_count): | |
freq, title = raw_input().split() | |
qi = -int(freq) * i | |
heappush(songs, (qi, i, title.strip())) | |
print '\n'.join([heappop(songs)[2] for _ in xrange(songs_count)]) | |
if __name__ == "__main__": | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment