-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2805.cpp
More file actions
48 lines (43 loc) · 927 Bytes
/
2805.cpp
File metadata and controls
48 lines (43 loc) · 927 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
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;
long long n, m; // n:나무수, m: 집에가져가려는길이
long long tree[1000001];
bool is_possible(long long mid)
{
long long sum = 0;
for (int i = 0; i < n; i++)
{
if (tree[i] > mid)
{
sum += tree[i] - mid;
}
}
return sum >= m;
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
for (int t = 0; t < n; t++)
{ // 나무의 개수
cin >> tree[t];
}
long long left = 0, right = 1000000000; // 자를수있는 최대대소길이 찾기
long long ret = 0;
while (left <= right)
{
long long mid = left + (right - left) / 2;
if (is_possible(mid))
{
ret = mid;
left = mid + 1;
}
else
{
right = mid - 1;
}
}
cout << ret;
}