forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproPriorityQueue.java
More file actions
54 lines (33 loc) · 1008 Bytes
/
proPriorityQueue.java
File metadata and controls
54 lines (33 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.*;
public class proPriorityQueue {
public static long solution(int n, int[] works) {
long answer = 0;
int n_idx = 0;
int buffer =0;
long total = 0;
PriorityQueue<Integer> AL = new PriorityQueue<>(Collections.reverseOrder());
for(int i : works)
AL.offer(i);
for(int i : works)
total += i;
//시간이 충분할경우 바로 종료
if(total <= n)
return 0;
while(n != n_idx)
{
n_idx++;
buffer = AL.poll();
AL.offer(--buffer);
}
for(int i : AL)
{
answer += Math.pow(i, 2);
}
return answer;
}
public static void main(String[] args) {
int[] works = {4,3,3};
int n = 4;
System.out.println(solution(n, works));
}
}