-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEKO.cpp
More file actions
54 lines (38 loc) · 719 Bytes
/
EKO.cpp
File metadata and controls
54 lines (38 loc) · 719 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
49
50
51
52
53
54
#include <bits/stdc++.h>
using namespace std;
const long long MOD= 1e9+7;
const int N = 1e6+10;
const double eps=1e-6;
int n;
long long m;
long long a[N];
bool totalWood(long long h){
long long sum=0;
for(int i=0;i<n;i++){
if(a[i]>=h)
sum+=a[i]-h;
}
return sum>=m;
}
int main(){
cin>>n>>m;
int maxx=-1;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]>maxx)
maxx=a[i];
}
long long l=0,h=maxx;
while(h-l>1){
long long mid=(l+h)/2;
if(totalWood(mid))
l=mid;
else
h=mid-1;
}
if(totalWood(h))
cout<<h<<endl;
else
cout<<l<<endl;
return 0;
}