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
- 러닝일지
- 시뮬레이션
- priorityqueue
- COS PRO
- BOJ
- SWEA
- 이분탐색
- 문제해결
- DP
- BFS
- 투포인터
- 알고리즘
- 문제풀이
- math
- 건강
- 문자열
- 코테
- 자바
- SQL
- 코딩테스트
- db
- dfs
- 프로그래머스
- MySQL
- greedy
- Java
- oracle
- 운동기록
- 백준
- binary search
Archives
- Today
- Total
슈콩
[BOJ] 백준 2512 예산 본문
[문제]
https://www.acmicpc.net/problem/2512
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static int n;
static int[] budget;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
n = Integer.parseInt(br.readLine());
budget = new int[n];
st = new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) {
budget[i] = Integer.parseInt(st.nextToken());
}
int m = Integer.parseInt(br.readLine());
Arrays.sort(budget);
int start = 0;
int end = budget[n-1];
while(start<=end) {
int mid = (start+end) / 2;
if(can(mid)<=m) {
start++;
}
else {
end--;
}
}
System.out.println(end);
}
private static int can(int mid) {
int cnt = 0;
for(int i=0;i<n;i++) {
if(budget[i]<=mid) {
cnt += budget[i];
}
else
cnt += mid;
}
return cnt;
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 15686 치킨 배달 (0) | 2025.09.23 |
|---|---|
| [BOJ] 백준 15685 드래곤 커브 (0) | 2025.09.23 |
| [BOJ] 백준 2473 세 용액 (0) | 2025.09.23 |
| [BOJ] 백준 15684 사다리 조작 (0) | 2025.09.23 |
| [BOJ] 백준 15683 감시 (0) | 2025.09.23 |