Skip to content

Commit d2bb4c0

Browse files
authored
Merge pull request #1307 from AlgorithmWithGod/Seol-JY
[20251103] BOJ / G5 / 콘센트 / 설진영
2 parents cdf3ba1 + 86a7a9c commit d2bb4c0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
String[] firstLine = br.readLine().split(" ");
9+
int N = Integer.parseInt(firstLine[0]);
10+
int M = Integer.parseInt(firstLine[1]);
11+
12+
String[] secondLine = br.readLine().split(" ");
13+
Integer[] times = new Integer[N];
14+
for (int i = 0; i < N; i++) {
15+
times[i] = Integer.parseInt(secondLine[i]);
16+
}
17+
18+
Arrays.sort(times, (a, b) -> b - a);
19+
20+
PriorityQueue<Long> pq = new PriorityQueue<>();
21+
for (int i = 0; i < M; i++) {
22+
pq.offer(0L);
23+
}
24+
25+
for (int time : times) {
26+
long minTime = pq.poll();
27+
pq.offer(minTime + time);
28+
}
29+
30+
long result = 0;
31+
while (!pq.isEmpty()) {
32+
result = Math.max(result, pq.poll());
33+
}
34+
35+
System.out.println(result);
36+
}
37+
}
38+
```

0 commit comments

Comments
 (0)