题目链接
为了之前立的写完试炼场的flag,开始从新手村写起……(我太鶸了,学一年OI没过新手村)
一道水题,按力气升序排序就好
#include<cstdio>
#include<algorithm>
using namespace std;
#define _rep(i,a,b) for(int i=(a);i<=(b);i++)
const int N=5e3+10;
int n,s,a,b,cnt;
struct node{
int x,y;
bool operator <(const node&rhs)const{
return y<rhs.y;}
}apple[N];
int main()
{
//freopen("in.txt","r",stdin);
scanf("%d%d%d%d",&n,&s,&a,&b);
_rep(i,1,n)scanf("%d%d",&apple[i].x,&apple[i].y);
sort(apple+1,apple+n+1);
_rep(i,1,n)
{
if(s<apple[i].y)break;
if(apple[i].x<=(a+b))cnt++,s-=apple[i].y;
}
printf("%d\n",cnt);
return 0;
}