czk111 @ 2023-01-13 15:35:03
#include <bits/stdc++.h>
using namespace std;
struct node{
int b,c;
}a[50005];
long long n,s,sum;
bool cmp(node a,node e){
if(a.c<e.c){
return true;
}
return false;
}
int main(){
int f,g,i=0;
cin>>n>>s;
cin>>f>>g;
for(int i=0;i<n;i++){
cin>>a[i].b>>a[i].c;
}
sort(a,a+n,cmp);
for(int i=0;i<n;i++){
if(f+g<a[i].b&&s>=a[i].c)continue;
sum++;
s-=a[i].c;
i++;
}
cout<<sum;
}
by Zohn @ 2023-01-13 16:00:36
if(f+g<a[i].b&&s>=a[i].c)continue;
这一句有问题,应该改成
if(f+g<a[i].b || s<a[i].c) continue;
还有在最后的
i++;
要删掉