20求助必关
查看原帖
20求助必关
1344959
harry20120721楼主2025/7/1 19:12

只有20分求大佬指出问题

#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, s, a, b;
	cin >> n >> s >> a >> b;
	int x[n], y[n];
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	int h = a + b;
	sort(x, x + n);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n - i - 1; ++j) {
			if (x[j] > x[j + 1]) {
				swap(x[j], x[j + 1]);
				swap(y[j], y[j + 1]);
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < x[n]; i++) {
		if (h > x[i] && s > y[i]) {
			s -= y[i];
			ans++;
		} else {
			cout << ans;
			return 0;
		}
	}
	cout << ans;
	return 0;
}
2025/7/1 19:12
加载中...