60分求助
查看原帖
60分求助
651775
lizhaoqi楼主2023/12/18 20:51
#include<bits/stdc++.h>
using namespace std;
int n,s,a,b,cah,cnt;
struct node{
	int high,stren,can=1;
}apple[5005];
int cmp(node x,node y){
	if(x.can>y.can){
		return x.can>y.can;
	}else{
		return x.stren<y.stren;
	}
}
int main(){
	cin>>n>>s>>a>>b;
	cah=a+b;
	for(int i=1;i<=n;i++){
		cin>>apple[i].high>>apple[i].stren;
		if(apple[i].high>cah){
			apple[i].can=0;
		}
	}
	sort(apple+1,apple+n+1,cmp);
	int i=1;
	while(s>0){
		if(apple[i].can==0){			
			break;
		}
		s-=apple[i].stren;
		cnt++;
//		cout<<apple[i].high<<" "<<apple[i].stren<<" "<<apple[i].can<<" "<<s<<endl;
		i++;
	}
	if(s<0){
		cnt--;
	}
	cout<<cnt;
	return 0;
}

(备注:node是苹果的相关信息,high是高度,stren是花费的力气,can是能否能够到)

2023/12/18 20:51
加载中...