Skip to content

Instantly share code, notes, and snippets.

@marconi
Last active December 19, 2015 08:58
Show Gist options
  • Save marconi/5929095 to your computer and use it in GitHub Desktop.
Save marconi/5929095 to your computer and use it in GitHub Desktop.
A slightly faster zipfsong implementation.
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