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 f5fac54

Browse files
committed
배수빈: [BOJ] 17951 흩날리는 시험지 속에서 내 평점이 느껴진거야_250406
1 parent 8b92f9a commit f5fac54

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

‎BOJ/15001-20000번/SB_17951.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.StringTokenizer;
5+
6+
// 최솟값의 최댓값 구하기
7+
public class SB_17951 {
8+
static int N, K;
9+
static int[] arr;
10+
11+
private static boolean canDiv(int target) {
12+
int cnt = 0;
13+
int sum = 0;
14+
for (int a : arr) {
15+
sum+=a;
16+
if (sum >= target) {
17+
cnt++;
18+
sum = 0;
19+
}
20+
}
21+
return cnt >= K;
22+
}
23+
public static void main(String[] args) throws IOException {
24+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
25+
StringTokenizer st = new StringTokenizer(br.readLine());
26+
27+
N = Integer.parseInt(st.nextToken());
28+
K = Integer.parseInt(st.nextToken());
29+
30+
arr = new int[N];
31+
int mx = 0;
32+
st = new StringTokenizer(br.readLine());
33+
for (int i = 0; i < N; i++) {
34+
arr[i] = Integer.parseInt(st.nextToken());
35+
mx += arr[i];
36+
}
37+
38+
int l = 0;
39+
int h = mx;
40+
int ans = 0;
41+
while (l <= h) {
42+
int mid = (l + h) / 2;
43+
if (canDiv(mid)) {
44+
ans = mid;
45+
l = mid+1;
46+
}else {
47+
h = mid-1;
48+
}
49+
}
50+
System.out.println(ans);
51+
}
52+
53+
}

0 commit comments

Comments
(0)

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