240224 야근 지수

Jongleee·2024년 2월 24일
0

TIL

목록 보기
504/576
public long solution(int n, int[] works) {
	long answer = 0;

	PriorityQueue<Integer> maxHeap = new PriorityQueue<>((a, b) -> b - a);

	for (int work : works) {
		maxHeap.offer(work);
	}

	while (n > 0) {
		int maxWork = maxHeap.poll();
		if (maxWork == 0)
			break;
		maxHeap.offer(maxWork - 1);
		n--;
	}

	for (Integer work : maxHeap) {
		answer += (long) work * work;
	}

	return answer;
}

출처:https://school.programmers.co.kr/learn/courses/30/lessons/12927

0개의 댓글