P4165 [SCOI2007]组队

返回主页

感谢Twilight_Sx的题解

按身高排序,枚举身高最小值,原式

\[A\times(H-minh)+B\times(V-minv)\le C\\ A\times H+B\times V-C\le A\times minh+B\times minv \]

固定常量,令\(S_x=A\times H_x-C-A\times minh\)

\[S_x+B\times V_x\le B\times minv \]

移项可得

\[V_x-minv\le \frac{-S_x}B \]

又因为

\[V_x\ge minv \]

所以\(\frac{S_x}B+V_x\le minv \le V_x\) ,

所以我们在\(v\)范围上差分,取最大值即可

int n,A,B,C,mx,ans,a[10005];
struct node{
	int v,h;
	friend bool operator < (const node &a,const node &b){
		return a.h < b.h;
	}
}p[N];
void work(int x){
	int T = p[x].h * A;
	for(int i = x;i <= n;++i){
		int l = max(0,p[i].v - (T - A*p[i].h + C)/B);
		int r = p[i].v;
		if(l > r) continue;
		++a[l]; --a[r+1];
	}
	for(int i = 0,tem = 0;i <= mx;++i){
		a[i] += tem; tem = a[i];
		ans = max(ans,a[i]); a[i] = 0;
	}
}
int main(){
	n = read(); A = read(); B = read(); C = read();
	for(int i = 1;i <= n;++i){
		p[i].h = read(); p[i].v = read();
		mx = max(mx,p[i].v);
	}
	sort(p + 1,p + n + 1);
	for(int i = n;i >= 1;--i) work(i);
	printf("%d\n",ans);
}
posted @ 2020-10-22 09:28  INFP  阅读(67)  评论(0编辑  收藏  举报