CF 1042A Benches——二分答案(水题)

时间:2023-11-10 11:37:14

题目:http://codeforces.com/problemset/problem/1042/A

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int n,m,a[N],ans,mx;
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
mx=max(mx,a[i]);
}
int l=mx,r=mx+m;
while(l<=r)
{
int mid=l+r>>,sum=;
for(int i=;i<=n;i++)
sum+=mid-a[i];
if(sum>=m)ans=mid,r=mid-;
else l=mid+;
}
printf("%d %d\n",ans,mx+m);
return ;
}