HbugU @ 2021-05-02 07:11:03
根本想不出来哪里错了!求助!
#include<bits/stdc++.h>
using namespace std;
int n,s,a,b,h,ans=0,p[5005],q[5005];
struct node{
int x,y;
}apple[5005];
bool cmp(node e,node f){
return e.y<f.y;
}
int main(){
cin>>n>>s>>a>>b;
h=a+b;
int j=0;
for(int i=0;i<n;i++){
cin>>p[i]>>q[i];
if(p[i]<=h){
apple[j].x=p[i];
apple[j].y=q[i];
j++;
}
}
sort(apple,apple+j-1,cmp);
j=0;
int t=0;
while(s>=apple[t].y){
ans+=1;
s-=apple[t].y;
t++;
}
cout<<ans;
return 0;
}
by kiki5 @ 2021-06-19 14:11:01
仔细看看,你循环错了。