题解
2024-08-05 13:29:22
发布于:浙江
23阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
struct Apple{
int height,qe;
};
bool rt(const Apple& a, const Apple& b) {
return a.qe<b.qe;
}
int mx(int n,int s,int a,int b,vector<Apple>& apples) {
sort(apples.begin(), apples.end(), rt);
int count=0;
for(const auto& apple : apples) {
if(s>=apple.qe) {
if (apple.height<=b || (apple.height-a)<=b) {
s-=apple.qe;
count++;
}
}
else{
break;
}
}
return count;
}
int main() {
int n, s, a, b;
cin>>n>>s>>a>>b;
vector<Apple>apples(n);
for (int i=0;i<n;i++) {
cin>>apples[i].height>>apples[i].qe;
}
cout<<mx(n, s, a, b, apples);
return 0;
}
这里空空如也
有帮助,赞一个