forked from encrypted-def/basic-algo-lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2805.cpp
More file actions
39 lines (33 loc) · 774 Bytes
/
2805.cpp
File metadata and controls
39 lines (33 loc) · 774 Bytes
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
32
33
34
35
36
37
38
39
// Authored by : unluckyjung
// Co-authored by : BaaaaaaaaaaarkingDog
// http://boj.kr/0d301f4f0b4e4beebc7889e220b0145f
#include <bits/stdc++.h>
using namespace std;
int tree[1000002];
int n, m;
// x만큼 잘라냈을 때 남는 나무의 길이가 m 이상인가?
bool solve(int x) {
long long cur = 0;
for (int i = 0; i < n; ++i) {
if (tree[i] <= x) continue;
cur += (tree[i] - x);
}
return cur >= m;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i)
cin >> tree[i];
int st = 0;
int en = *max_element(tree, tree+n);
while (st < en) {
int mid = (st+en+1)/2;
if (solve(mid))
st = mid;
else
en = mid - 1;
}
cout << st;
}