본문 바로가기

Coding Test/Programmers

[프로그래머스/파이썬] 야근 지수

728x90

 

나의 풀이

from functools import reduce
import heapq

def solution(n, works):
    if sum(works) <= n:
        return 0
    works = [-x for x in works]
    heapq.heapify(works)
    for _ in range(n):
        heapq.heappush(works, heapq.heappop(works) + 1)
    return reduce(lambda x, y : x + y ** 2, works, 0)
반응형