抄
2025-05-24 17:18:08
发布于:上海
9阅读
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) << endl;
return 0;
}
这里空空如也
有帮助,赞一个