#include<iostream>
#include<algorithm>
using namespace std;
int n, s, a, b;
struct Apple
{
int x, y;
}apple[5005];
bool compare(const Apple& a, const Apple& b)
{
return a.y < b.y;
}
int main()
{
int i, j;
Apple temp;
cin >> n >> s >> a >> b;
if (0 == s)
cout << '0';
else
{
for (i = 0, j = 0; i < n; i++)
{
cin >> temp.x >> temp.y;
if (temp.x <= a + b)
{
apple[j] = temp;
j++;
}
}
sort(apple, apple + j, compare);
for (i = 0; i < j && s >= 0; i++)
s -= apple[i].y;
if (0 == i)
cout << '0';
else
cout << i - 1;
}
return 0;
}
洛谷P1478 陶陶摘苹果(升级版)进阶解法
最新推荐文章于 2025-10-28 21:08:07 发布
这是一个C++程序,用于读取苹果的位置信息,根据位置筛选出在指定范围内的苹果,并按照位置的y轴进行排序。程序首先对输入的苹果数组进行过滤,然后使用sort函数对符合条件的苹果进行升序排列,最后计算并输出可以被覆盖的苹果数量。
1902

被折叠的 条评论
为什么被折叠?



