Huayecai @ 2024-09-11 20:55:41
#include<bits/stdc++.h>
using namespace std;
struct apple{
int c,d;
}p[5050];
bool hh(apple x,apple y){
return x.d<y.d;
}
int main(){
int n,s,a,b;
cin>>n>>s;
cin>>a>>b;
int can=0;
for(int i=0;i<n;i++){
int l,k;
cin>>l>>k;
if(l<=a+b){
p[can].c=l;
p[can].d=k;
can+=1;
}
}
sort(p,p+can,hh);
int j=0,sum=0;
while(s>=0){
j+=1;
sum+=1;
s-=p[j].d;
}
cout<<sum<<endl;
}
by 玉树临风英俊潇洒 @ 2024-09-11 21:02:55
只要特判0 0就行了 已AC
#include<bits/stdc++.h>
using namespace std;
struct apple{
int c,d;
}p[5050];
bool hh(apple x,apple y){
return x.d<y.d;
}
int main(){
int n,s,a,b;
cin>>n>>s;
cin>>a>>b;
if(n==0&&s==0){cout<<0;return 0;}
int can=0;
for(int i=0;i<n;i++){
int l,k;
cin>>l>>k;
if(l<=a+b){
p[can].c=l;
p[can].d=k;
can+=1;
}
}
sort(p,p+can,hh);
int j=0,sum=0;
while(s>=0){
j+=1;
sum+=1;
s-=p[j].d;
}
cout<<sum<<endl;
}
求关
by Huayecai @ 2024-09-23 14:24:24
@Dalong37 感谢已关
by 玉树临风英俊潇洒 @ 2024-09-23 22:11:07
@Huayecai 哎?你不上学
by Huayecai @ 2024-09-25 19:33:30
@Dalong37 没晚自习
by 玉树临风英俊潇洒 @ 2024-09-25 20:04:24
@Huayecai 但是你3点回的(我也才4:30放学
by Huayecai @ 2024-09-25 20:15:21
@Dalong37 哦,想起来了,信息课上登的洛谷(难绷)
by 玉树临风英俊潇洒 @ 2024-09-25 20:17:32
@Huayecai 你几年级
by 玉树临风英俊潇洒 @ 2024-09-25 20:18:24
@Huayecai 为什么8年级没信息课
by Huayecai @ 2024-09-25 20:19:55
@Dalong37 高一
by Huayecai @ 2024-09-25 20:20:12
@Dalong37 学校问题吧