Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9746f83

Browse files
이지영: [PG] 야근지수_240912
1 parent 77f6990 commit 9746f83

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
5+
static class State implements Comparable<State>{
6+
int work;
7+
public State(int work){
8+
this.work = work;
9+
}
10+
@Override
11+
public int compareTo(State other){
12+
return other.work - this.work;
13+
}
14+
@Override
15+
public String toString(){
16+
return "w:"+this.work;
17+
}
18+
}
19+
20+
public long solution(int n, int[] works) {
21+
long answer = 0;
22+
long total = 0;
23+
24+
PriorityQueue<State> pq = new PriorityQueue<>();
25+
for(int work: works){
26+
total += work;
27+
pq.add(new State(work));
28+
}
29+
// 작업량이 n보다 작으면 피로도 없음
30+
if(total <= n){
31+
return answer;
32+
}
33+
34+
// 우선순위 큐를 이용해서 작업량이 많은 순으로 출력
35+
for(int i=0; i<n; i++){
36+
State now = pq.poll();
37+
now.work--;
38+
pq.add(now);
39+
}
40+
// System.out.println(pq);
41+
42+
while(!pq.isEmpty()){
43+
State now = pq.poll();
44+
if(now.work > 0){
45+
answer += (now.work*now.work);
46+
}
47+
}
48+
49+
return answer;
50+
}
51+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /