P4165 [SCOI2007]组队

# include <bits/stdc++.h>
# define re register
# define N 5050
using namespace std;
int n,a,b,c;
int ans;

struct node
{
int h;//高度
int v;//速度
int sum;
}e[N];

int cmp1(const node &a,const node &b) {return a.h>b.h;}//按高度排序
int cmp2(const node &a,const node &b) {return a.sum>b.sum;}//按总属性排序

node f[N];

int main()
{
ios::sync_with_stdio(false);

cin>>n>>a>>b>>c;
for(int i = 1; i <= n; i++)
{
cin>>e[i].h>>e[i].v;
e[i].sum = a*e[i].h + b*e[i].v;//总属性
f[i] = e[i];
}

sort(e+1,e+n+1,cmp1);
sort(f+1,f+n+1,cmp2);

int l,r,cnt;

for(int i = 1; i <= n; i++)
{
l = r = 0;
cnt = 0;
int maxn = e[i].v + c/b;
for(int j = 1; j <= n; j++)
{
while(r < n && f[r+1].sum <= a*e[j].h+b*e[i].v+c)
{
r++;
if(f[r].v >= e[i].v && f[r].v <= maxn) cnt++;
}
while(l < n && e[l+1].h < e[j].h)
{
l++;
if(e[l].v >= e[i].v && e[l].v <= maxn) cnt--;
}
}
ans = max(ans , cnt);
}

cout<<ans<<endl;
return 0;
}

posted @ 2018-09-04 16:39  Lalenture  阅读(90)  评论(0编辑  收藏  举报
//一下两个链接最好自己保存下来,再上传到自己的博客园的“文件”选项中