题目即要求$Ah+Bv<=C+Aminh+Bminv$,如果同时枚举minh和minv,那么即要求$minhle h$,$minvle v$且$sle C+Aminh+Bminv$
从小到大枚举minh,然后答案可以理解为所有s合法-v合法且s合法,对于两个在枚举minv的时候预处理即可
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n,l,r,s,ans,A,B,C; 4 struct ji{ 5 int h,v,s; 6 }a[100005],b[100005]; 7 bool cmp1(ji x,ji y){ 8 return x.h<y.h; 9 } 10 bool cmp2(ji x,ji y){ 11 return x.s<y.s; 12 } 13 int main(){ 14 scanf("%d%d%d%d",&n,&A,&B,&C); 15 for(int i=1;i<=n;i++){ 16 scanf("%d%d",&a[i].h,&a[i].v); 17 a[i].s=a[i].h*A+a[i].v*B; 18 b[i]=a[i]; 19 } 20 sort(a+1,a+n+1,cmp1); 21 sort(b+1,b+n+1,cmp2); 22 for(int i=1;i<=n;i++){ 23 int m1=a[i].v,m2=a[i].v+C/B; 24 l=r=s=0; 25 for(int j=1;j<=n;j++){ 26 while ((r<n)&&(b[r+1].s-A*a[j].h-B*a[i].v<=C)) 27 if ((m1<=b[++r].v)&&(b[r].v<=m2))s++; 28 while ((l<n)&&(a[l+1].h<a[j].h)) 29 if ((m1<=a[++l].v)&&(a[l].v<=m2))s--; 30 ans=max(ans,s); 31 } 32 } 33 printf("%d",ans); 34 }