Skip to content

[1주차] 이혜원 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
이혜원: [PG] 12927 야근 지수_240912
  • Loading branch information
icegosimperson committed Sep 12, 2024
commit d7cda1b89cca9be5da143abcaea4ef42d532b6df
32 changes: 32 additions & 0 deletions Programmers/Level3/HW_12927.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.util.*;

// n : 퇴근시간까지 남은 시간
// works : 작업량
class Solution {
public long solution(int n, int[] works) {
long answer = 0; // 야근 피로도 = 시작한 시점에서 (남은 일의 작업량)^2
PriorityQueue<Integer> Queue = new PriorityQueue<>(Comparator.reverseOrder()); // 높은 숫자 우선순위 큐 정의

for(int i=0; i<works.length; i++){
Queue.offer(works[i]); // offer() : 우선순위 큐에 원소 추가, 실패시 false 반환
}

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

int size = Queue.size(); // Queue size 줄어드는 것 방지
for(int i=0; i<size; i++){
int work = Queue.poll();
answer += work * work;
}

return answer;
}
}