2490: 【作】【普及-】【P1478】 陶陶摘苹果(升级版)

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:16 解决:2

题目描述

又是一年秋季时,陶陶家的苹果树结了 lns="http://www.w3.org/1998/Math/MathML"> 个果子。陶陶又跑去摘苹果,这次他有一个 lns="http://www.w3.org/1998/Math/MathML"> 公分的椅子。当他手够不着时,他会站到椅子上再试试。

这次与 NOIp2005 普及组第一题不同的是:陶陶之前搬凳子,力气只剩下 lns="http://www.w3.org/1998/Math/MathML"> 了。当然,每次摘苹果时都要用一定的力气。陶陶想知道在 lns="http://www.w3.org/1998/Math/MathML"><0 之前最多能摘到多少个苹果。

现在已知 lns="http://www.w3.org/1998/Math/MathML"> 个苹果到达地上的高度 lns="http://www.w3.org/1998/Math/MathML">,椅子的高度 lns="http://www.w3.org/1998/Math/MathML">,陶陶手伸直的最大长度 lns="http://www.w3.org/1998/Math/MathML">,陶陶所剩的力气 lns="http://www.w3.org/1998/Math/MathML">,陶陶摘一个苹果需要的力气 lns="http://www.w3.org/1998/Math/MathML">,求陶陶最多能摘到多少个苹果。

输入

第 lns="http://www.w3.org/1998/Math/MathML">1 行:两个数 苹果数 lns="http://www.w3.org/1998/Math/MathML">,力气 lns="http://www.w3.org/1998/Math/MathML">

第 lns="http://www.w3.org/1998/Math/MathML">2 行:两个数 椅子的高度 lns="http://www.w3.org/1998/Math/MathML">,陶陶手伸直的最大长度 lns="http://www.w3.org/1998/Math/MathML">

第 lns="http://www.w3.org/1998/Math/MathML">3 行~第 lns="http://www.w3.org/1998/Math/MathML">3+1 行:每行两个数 苹果高度 lns="http://www.w3.org/1998/Math/MathML">,摘这个苹果需要的力气 lns="http://www.w3.org/1998/Math/MathML">

输出

只有一个整数,表示陶陶最多能摘到的苹果数。

样例输入 复制

8 15
20 130
120 3
150 2
110 7
180 1
50 8
200 0
140 3
120 2

样例输出 复制

4

提示

对于 lns="http://www.w3.org/1998/Math/MathML">100% 的数据,lns="http://www.w3.org/1998/Math/MathML">5000lns="http://www.w3.org/1998/Math/MathML">50lns="http://www.w3.org/1998/Math/MathML">200lns="http://www.w3.org/1998/Math/MathML">1000lns="http://www.w3.org/1998/Math/MathML">280lns="http://www.w3.org/1998/Math/MathML">100

#include<bits/stdc++.h>
using namespace std;
struct apple{
	int x;
	int y;
}p[5010];
int n,s,a,b,ans=0;
int cmp(apple a1,apple a2) {
	if (a1.y!=a2.y)
	    return a1.y<a2.y;
	else
	    return a1.x<a2.x;
}
int main(){
    cin>>n>>s>>a>>b;
    for (int i=1;i<=n;i++) {
    	cin>>p[i].x>>p[i].y;
	}
	sort(p+1,p+n+1,cmp);
	for (int i=1;i<=n;i++) {
		if (p[i].x<=a+b && (s-=p[i].y)>=0) ans++;
		if (s<0) break;
	}
    cout<<ans<<endl;
	return 0;
}