为啥只有40分
查看原帖
为啥只有40分
677150
ThEskY_B1ackeR楼主2022/8/8 19:17
#include<bits/stdc++.h>
using namespace std;
struct t1{
	int x,y;//x=苹果高度,y=需要力气。 
}apples[5005];
int main(){
	int n,s,a,b;//n=数量,s=剩余力气,a=椅子高度,b=手伸直的最大长度。 
	cin>>n>>s>>a>>b;
	int num=0;
	for(int i=0;i<n;i++){
		int TU_height,TU_power;
		cin>>TU_height>>TU_power;
		if(TU_height<=a+b && TU_power<=s)apples[i].x=TU_height,apples[i].y=TU_power,num++;
	}
	int ans=0;
	for(int i=0;i<num-1;i++){
		for(int j=num-1;j>i;j--) if(apples[j].y<apples[j-1].y){
			int TU_number1=apples[j].x,TU_number2=apples[j].y;
			apples[j].x=apples[j-1].x,apples[j].y=apples[j-1].y;
			apples[j-1].x=TU_number1,apples[j-1].y=TU_number2;
		}
		s-=apples[i].y;
		if(s>=0) ans++;
		else break;
	}
	if(s-apples[num-1].y>=0)ans++;
	cout<<ans;
	return 0;
}
2022/8/8 19:17
加载中...