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
- coding
- 코딩
- 문제풀이
- OS
- Operating System
- 오에스
- 너비우선탐색
- bfs
- 구현
- Stack
- 정석
- 개발
- c++
- 브루트포스
- 정석학술정보관
- 자료구조
- vector
- 북리뷰
- 백준
- 컴퓨터공학과
- cs
- 오퍼레이팅시스템
- Computer science
- DP
- 그래프
- 알고리즘
- 컴공과
- 코테
- 스택
- 컴공
Archives
- Today
- Total
Little Jay
[C++] 백준 2805번 나무 자르기 본문
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MAX = 1000000;
long long arr[MAX];
long long M;
int N;
bool can(long long height) {
long long len = 0;
for (int i = 0; i < N; i++) {
if (arr[i] - height > 0)
len += arr[i] - height;
}
if (len >= M)
return true;
else
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
long long low = 1, high = 0;
for (int i = 0; i < N; i++) {
cin >> arr[i];
high = max(high, arr[i]);
}
long long result = 0;
while (low <= high) {
long long mid = (low + high) / 2;
if (can(mid)) {
result = max(result, mid);
low = mid + 1;
}
else {
high = mid - 1;
}
}
cout << result << "\n";
return 0;
}
'알고리즘 > BOJ' 카테고리의 다른 글
[C++] 백준 2839번 - 설탕 배달 (0) | 2021.08.04 |
---|---|
[C++] 백준 12605번 단어순서 뒤집기 (0) | 2021.08.04 |
[C++] 백준 1021번 회전하는 큐 (0) | 2021.08.04 |
[C++] 백준 4949번 균형잡힌 세상 (0) | 2021.08.03 |
[C++] 백준 1181번 단어 정렬 (0) | 2021.08.02 |
Comments