728x90
※ SW Expert 아카데미의 문제를 무단 복제하는 것을 금지합니다.
728x90
메모리: 27,140 KB, 시간: 147 ms
사용 알고리즘: 이분탐색
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
StringBuilder result = new StringBuilder();
int T = Integer.parseInt(br.readLine());
for (int tc = 1; tc <= T; tc++) {
st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
long M = Long.parseLong(st.nextToken());
Long[] candies = new Long[N];
st = new StringTokenizer(br.readLine());
long m = 0;
for (int i = 0; i < N; i++) {
candies[i] = Long.parseLong(st.nextToken());
m = Math.max(m, candies[i]);
}
long s = 1, e = m;
long ans = 0;
while(s <= e) {
long mid = (s + e) / 2;
long p = M;
for (int i = 0; i < N; i++) {
p -= (candies[i] - (candies[i] % mid)) / mid;
if(p <= 0) break;
}
if(p <= 0) {
ans = Math.max(ans, mid);
s = mid + 1;
}
else e = mid - 1;
}
result.append("#" + tc + " " + ans + "\n");
}
System.out.println(result);
}
}
728x90
'Problem Solving > SWEA' 카테고리의 다른 글
[SW Expert Academy, SWEA 1251] [응용문제] 하나로 (java) (0) | 2024.01.17 |
---|---|
[SW Expert Academy, SWEA 1232] 사칙연산 (java) (0) | 2024.01.16 |
[SW Expert Academy, SWEA 10507] 영어 공부 (java) (0) | 2023.07.09 |
[SW Expert Academy, SWEA 9843] 촛불 이벤트 (java) (1) | 2023.06.15 |
[SW Expert Academy, SWEA 13736] 사탕 분배 (java) (0) | 2023.05.06 |