题解 P1478 【陶陶摘苹果(升级版)】
轩槿
·
·
题解
#include<iostream>
#include<map>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
struct apple{//开个结构体就好哩
int x;
int y;
}gi[50005];
bool cmp(struct apple a,struct apple b)
{
return a.y<b.y;
}
int main(){
freopen("ii.in","r",stdin);
freopen("ii.out","w",stdout);
int n,s,a,b,ans=0;
cin>>n>>s>>a>>b;
for(int i=0;i<n;i++)cin>>gi[i].x>>gi[i].y;
sort(gi,n+gi,cmp);
for(int i=0;i<n;i++)
{
if(s-gi[i].y<0)break;
if(gi[i].x>a+b)continue;
else {s-=gi[i].y;ans++;}
}
cout<<ans;
return 0;
}