求助!只有40分!
查看原帖
求助!只有40分!
510360
HbugU楼主2021/5/26 21:01
#include<bits/stdc++.h>
using namespace std;
int n,s,a,b,h,ans=0,p[5005],q[5005];
struct node{
	int x,y;
}apple[5005];
bool cmp(node e,node f){
	return e.y<f.y;
}
int main(){
	cin>>n>>s>>a>>b;
	h=a+b;
	int j=0;
	for(int i=0;i<n;i++){
		cin>>p[i]>>q[i];
		if(p[i]<=h){
			apple[j].x=p[i];
			apple[j].y=q[i];
			j++;
		}
	}
	sort(apple,apple+j-1,cmp);
	j=0;
	int t=0;
	while(s>=apple[t].y){
		ans+=1;
		s-=apple[t].y;
		t++;
	}
	cout<<ans;
	return 0;
}

2021/5/26 21:01
加载中...