Files
python/TangDou/LuoGuBook/P1478.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

34 lines
836 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5010;
int n, s; //苹果数 n力气 s
int a, B; //椅子的高度a陶陶手伸直的最大长度b。
struct apple {
int x, y;
} apples[N];
bool cmp(const apple &a, const apple &b) {
return a.y < b.y;
}
int cnt; //结果数
//每行两个数 苹果高度 xi,摘这个苹果需要的力气yi
int main() {
cin >> n >> s >> a >> b;
for (int i = 1; i <= n; i++) cin >> apples[i].x >> apples[i].y;
//排序
sort(apples + 1, apples + 1 + n, cmp);
for (int i = 1; i <= n; i++)
if (a + b >= apples[i].x && s >= apples[i].y) {//能够的到,而且力气够用
cnt++;
s -= apples[i].y;
}
//输出大吉
cout << cnt << endl;
return 0;
}