lighthouse @ 2021-07-09 15:53:42
#include <bits/stdc++.h>
using namespace std;
struct apple{
int x, y;
}ap[5100];
bool cmp(apple x, apple y){
return x.y <= y.y;
}
int main(){
int n, s, a, b;
scanf("%d%d%d%d", &n, &s, &a, &b);
int ans = 0;
for(int i = 0;i < n;i++){
scanf("%d%d", &ap[i].x, &ap[i].y);
}
sort(ap, ap + n, cmp);
for(int i = 0;i < n;i++){
if(ap[i].x > (a + b)) continue;
if(s < ap[i].y) break;
s -= ap[i].y;
ans++;
}
cout << ans;
return 0;
}
第三个点和第五个点RE,求助
by _Sparkle @ 2021-07-09 15:58:02
@lighthouse
bool cmp(apple x, apple y){
return x.y <= y.y; // ? ? ???? ????? ? ????
}
bool cmp(apple x, apple y){
return x.y < y.y;
}
by Rui_R @ 2021-07-09 15:58:44
@lighthouse 比较经典的错误了,把 cmp
里面的等于号删掉
by lighthouse @ 2021-07-09 15:59:52
@cheerful_yuyu @Rui_R 谢