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
- math
- 러닝일지
- BFS
- 코테
- MySQL
- greedy
- binary search
- 자바
- 문제해결
- COS PRO
- priorityqueue
- 문제풀이
- BOJ
- SQL
- 시뮬레이션
- 알고리즘
- oracle
- 이분탐색
- 운동기록
- 투포인터
- DP
- 프로그래머스
- dfs
- db
- 백준
- 코딩테스트
- 문자열
- 건강
- SWEA
- Java
Archives
- Today
- Total
슈콩
[BOJ] 백준 2805 나무 자르기 본문

[문제]
https://www.acmicpc.net/problem/2805
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static int n;
static long m;
static int[] arr;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Long.parseLong(st.nextToken());
st = new StringTokenizer(br.readLine());
arr = new int[n];
for(int i=0;i<n;i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(arr);
long start = 0;
long end = arr[arr.length-1];
while(start<=end) {
long mid = (start + end) / 2;
if(possible(mid))
start = mid + 1;
else
end = mid - 1;
}
System.out.println(end);
}
private static boolean possible(long val) {
long cnt = 0;
for(int i=0;i<n;i++) {
if(arr[i]>val) cnt += arr[i] - val;
}
if(cnt<m) return false;
return true;
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 21921 블로그 (0) | 2025.11.11 |
|---|---|
| [BOJ] 백준 3151 합이 0 (0) | 2025.10.06 |
| [BOJ] 백준 9935 문자열 폭발 (0) | 2025.10.04 |
| [BOJ] 백준 28215 대피소 (0) | 2025.10.04 |
| [BOJ] 백준 13458 시험 감독 (0) | 2025.10.02 |