Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- SWEA
- math
- 시뮬레이션
- db
- 투포인터
- binary search
- 러닝일지
- 코테
- greedy
- SQL
- Java
- 운동기록
- MySQL
- 자바
- DP
- 문제풀이
- 이분탐색
- 문자열
- 코딩테스트
- dfs
- 알고리즘
- 건강
- 문제해결
- BFS
- 백준
- oracle
- priorityqueue
- BOJ
- 프로그래머스
- COS PRO
Archives
- Today
- Total
슈콩
[BOJ] 백준 16401 과자 나눠주기 본문
[문제]
https://www.acmicpc.net/problem/16401
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static int m,n;
static int[] snack;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
m = Integer.parseInt(st.nextToken());
n = Integer.parseInt(st.nextToken());
snack = new int[n];
st = new StringTokenizer(br.readLine());
int max = 0;
for(int i=0;i<n;i++) {
snack[i] = Integer.parseInt(st.nextToken());
if(max < snack[i]) max = snack[i];
}
int start = 1;
int end = max;
while(start<=end) {
int mid = (start+end) / 2;
if(can(mid)) {
start = mid + 1;
}
else
end = mid - 1;
}
System.out.println(end);
}
private static boolean can(int mid) {
int cnt = 0;
for(int i=0;i<n;i++) {
cnt += snack[i] / mid;
}
return cnt >= m;
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 14502 연구소 (2) | 2025.09.19 |
|---|---|
| [BOJ] 백준 14499 주사위 굴리기 (0) | 2025.09.19 |
| [BOJ] 백준 14921 용액 합성하기 (0) | 2025.09.18 |
| [BOJ] 백준 13460 구슬 탈출 2 (2) | 2025.09.18 |
| [BOJ] 백준 1477 휴게소 세우기 (0) | 2025.09.18 |