Skip to content

Commit d502748

Browse files
authored
[20250811] BOJ / G5 / 콘센트 / 김수연
[20250811] BOJ / G5 / 콘센트 / 김수연
2 parents 7c1ef09 + 3034567 commit d502748

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class boj23843 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
public static void main(String[] args) throws Exception {
12+
nextLine();
13+
int N = nextInt();
14+
int M = nextInt();
15+
int answer = 0;
16+
Integer[] t = new Integer[N];
17+
PriorityQueue<Integer> pq = new PriorityQueue<>();
18+
nextLine();
19+
for (int i = 0; i < N; i++) t[i] = nextInt();
20+
Arrays.sort(t);
21+
for (int i = 0; i < M; i++) {
22+
pq.add(0);
23+
}
24+
for (int i = N - 1; i >= 0; i--) {
25+
int tmp = pq.poll() + t[i];
26+
pq.add(tmp);
27+
}
28+
while (!pq.isEmpty()) {
29+
answer = Math.max(pq.poll(), answer);
30+
}
31+
System.out.println(answer);
32+
}
33+
}
34+
```

0 commit comments

Comments
 (0)