# 베스트앨범

베스트앨범 - 프로그래머스

def solution(genres, plays):
    answer = []
    d = dict()
    play_d = dict()
    for i in range(len(genres)):
        genre = genres[i]
        play = plays[i]
        play_d[genre] = play_d.get(genre, 0) + play
        d[genre] = d.get(genre, []) + [(play, i)]
    for (genre, _) in sorted(play_d.items(), key=lambda x: x[1], reverse=True):
        d[genre] = sorted(d[genre], key=lambda x: (-x[0], x[1]))
        answer += [idx for (_, idx) in d[genre][:2]]
    return answer