社区讨论

萌新求解!!!

P1478陶陶摘苹果(升级版)参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@m38nat1e
此快照首次捕获于
2024/11/08 19:20
去年
此快照最后确认于
2025/11/04 15:07
4 个月前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;

int n,s,a,b;
struct node{
	int x,y;
}apple[6000];

int cmp(node e,node h) {
	return e.y < h.y;
}

int main()
{
	cin >> n >> s;
	cin >> a >> b;
	for (int i = 1;i <= n;i++) {
		cin >> apple[i].x >> apple[i].y;
	}
	sort(apple + 1,apple + n + 1,cmp);
	int sum = 0;
	bool ans = 1;
	int i = 1;
	while (ans != 0 && i <= n){
		if (s >= apple[i].y && a + b >= apple[i].x) {
			s = s - apple[i].y;
			sum++;
			i++;
		}
		else{
			ans = 0;
		}
	}
	cout << sum;
	return 0;
}

回复

2 条回复,欢迎继续交流。

正在加载回复...