PAI0118 @ 2023-10-20 22:21:20
#include<bits/stdc++.h>
using namespace std;
int n,s,a,b,x[1000],y[1000],z[1000]={0};
int main()
{
cin>>n>>s>>a>>b;
for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
for(int i=1;i<=n;i++){
if(x[i]<=(a+b)){
z[i]=y[i];
}
}
int l;
for(int i=1;i<=n;i++){
if(z[i]>=0) l++;
cout<<z[i]<<" ";
}
int cnt=0;
sort(z,z+l);
for(int i=1;i<=l;i++){
if(s>=0){
s-=z[i];
cnt++;
}
}
cout<<cnt;
return 0;
}
by LoTLaneyyat @ 2023-12-04 13:48:13
@PAI0118
#include<bits/stdc++.h>
using namespace std;
const int N=1e8+10;
long long n,m,x,y,ans;
struct Node{
int b,c;
}a[N];
bool cmp(Node h,Node g){
return h.c <g.c ;
}
int main(){
cin>>n>>m;
cin>>x>>y;
for(int i=1;i<=n;i++){
cin>>a[i].b >>a[i].c ;
}
sort(a+1,a+1+n,cmp);
int sum=x+y;
for(int i=1;i<=n;i++){
if(a[i].b >sum){
continue;
}
if(a[i].b <=sum&&m>=a[i].c ){
ans++;
m=m-a[i].c ;
}
}
cout<<ans;
}