显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
long long n,a,b,l,r,mid,maxnum,temp,temp2,c,p[500010];
int main(void)
{
freopen("dry.in","r",stdin);
freopen("dry.out","w",stdout);
int i;
bool ok;
cin>>n>>a>>b;
for (i=1;i<=n;i++)
{
cin>>p[i];
if (maxnum<p[i])
maxnum=p[i];
}
l=0;
if (maxnum%a==0)
r=maxnum/a;
else
r=maxnum/a+1;
mid=(l+r)>>1;
if (b==0)
{
cout<<r<<endl;
return(0);
}
while (l<r)
{
ok=true;
c=0;
temp=a*mid;
for (i=1;i<=n;i++)
{
if (temp<p[i])
{
if ((p[i]-temp)%b==0)
temp2=(p[i]-temp)/b;
else
temp2=(p[i]-temp)/b+1;
c+=temp2;
if (c>mid)
{
ok=false;
break;
}
}
}
if (ok)
r=mid;
else
l=mid+1;
mid=(l+r)>>1;
}
cout<<mid<<endl;
return(0);
}