We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 77f6990 commit 9746f83Copy full SHA for 9746f83
Programmers/Level3/JY_야근지수.java
@@ -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
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
44
+ if(now.work > 0){
45
+ answer += (now.work*now.work);
46
47
48
49
50
51
+}
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments