Notice
Recent Posts
Recent Comments
Link
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