-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathEKO.cpp
More file actions
46 lines (42 loc) · 759 Bytes
/
EKO.cpp
File metadata and controls
46 lines (42 loc) · 759 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
#include<stdio.h>
#include<iostream>
using namespace std;
int a[1000005];
long long int n,m,i,maxi=0,store=0,l,h,mid,res;
int main()
{
scanf("%lld%lld",&n,&m);
for (i=0;i<n;i++)
{
scanf("%d",&a[i]);
if ( a[i] > maxi )
maxi = a[ i ];
}
l=0;
h=maxi;
while(l<=h)
{
mid=(l+h)/2;
res=0;
for(i=0;i<n;i++)
{
if(a[i]-mid > 0)
res=res+a[i]-mid;
}
if(res>m)
{
l=mid+1;
if(mid>store)
store = mid;
}
else if(res<m)
h=mid-1;
else
{
store = mid;
break;
}
}
printf( "%lld\n", store );
return 0;
}