题目传送门
这道题其实二分一下答案就okay了的 不过LL什么的有时候忘了加 被卡了下
#include<cstdio> #include<cstring> #include<algorithm> #define LL long long using namespace std; const int M=100007; int read(){int ans=0,f=1,c=getchar();while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}return ans*f; } int n,p,q,w; int s[M]; LL ans; bool check(LL x){LL now=x*q,tot=0;int top=n,v;while(top){if(s[top]<=now) break;if((s[top]-now)%w) v=(s[top]-now)/w+1;else v=(s[top]-now)/w;tot+=v;top--; }return tot<=x; } int main() {n=read(); p=read(); q=read(); w=p-q;for(int i=1;i<=n;i++) s[i]=read();sort(s+1,s+1+n);LL l=0,r=1e9;while(l<=r){LL mid=(l+r)>>1;if(check(mid)) ans=mid,r=mid-1;else l=mid+1;}printf("%lld\n",ans);return 0; }