|
| 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