OneMore14 @ 2021-02-04 11:59:57
#include <iostream>
#include <climits>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <stack>
#include <algorithm>
#include <cstring>
#include <set>
#include <unistd.h>
#include <map>
#include <sys/wait.h>
#define ll long long
using namespace std;
int n, s;
int a, b;
struct Node {
int h;
int w;
};
int len = 0;
Node list[5005];
bool cmp(Node x, Node y) {
return x.w < y.w; // 这里如果是 <=, 最后一个点会RE
}
int main() {
cin >> n >> s;
cin >> a >> b;
for (int i = 0; i < n; i++) {
int h, w;
cin >> h >> w;
if (h <= (a + b)) {
list[len].w = w;
list[len].h = h;
++len;
}
}
sort(list, list + len, cmp);
int ans = 0;
for (int i = 0; i < len; i++) {
if (s >= list[i].w) {
ans++;
s -= list[i].w;
}
if (s < 0) {
break;
}
}
cout << ans << endl;
return 0;
}
27行cmp函数里如果是<=,最后一个点就会RE,但换成<就不会,有什么说法吗?
by EternalAlexander @ 2021-02-04 12:01:57
https://www.cnblogs.com/walkerlala/p/5561339.html
by OneMore14 @ 2021-02-04 12:47:31
@EternalAlexander 明白了,感谢指路