真奇怪,每个测试点都过了,结果报热(RE)是怎么回事?
#include <bits/stdc++.h>
using namespace std;
int H[2000000],ans,temp,l,mid,r;
long long check(long long x,long long f)
{
long long sum=0,i;
for(i=1;i<=f;i++)
if (H[i]>x) sum+=H[i]-x;
return sum;
}
int main()
{
//COCI 砍树
long long N,M,i;
scanf("%d%d",&N,&M);
for(i=1;i<=N;i++)
{
scanf("%d",&H[i]);
temp=max(temp,H[i]);
}
l=0,r=temp;
while(l<=r)
{
mid=(l+r)/2;
if (check(mid,N)<M) r=mid-1;
else
{
ans=mid;
l=mid+1;
}
}
printf("%d",ans);
}
值得一提的是,开O2后竟然全哇(WA)了