Information
- ID
- 952
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 3
- Tags
- (None)
- # Submissions
- 71
- Accepted
- 27
- Uploaded By
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int a[N];
int n,m;
bool check(int x)
{
long long res=0; //总合
for(int i=1;i<=n;i++)
{
res=res+max(0,a[i]-x);
}
return res>=m; //当前长度是否可以符合要求
}
int main()
{
cin>>n>>m;
int l=0,r=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
r=max(r,a[i]);
}
while(l<r)
{
int mid=l+r+1>>1;
if(check(mid)) l=mid;
else r=mid-1;
}
cout<<l;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int a[N];
int n,m;
bool check(int x)
{
long long res=0;
for(int i=1;i<=n;i++)
{
res=res+max(0,a[i]-x);
}
return res>=m;
}
int main()
{
cin>>n>>m;
int l=0,r=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
r=max(r,a[i]);
}
while(l<r)
{
int mid=l+r+1>>1;
if(check(mid)) l=mid;
else r=mid-1;
}
cout<<l;
return 0;
}