soul2024 @ 2024-07-31 10:47:43
#include<bits/stdc++.h>
using namespace std;
int n,s,a,b,ans;
struct edge{
int x,y;
}e[5005];
bool cmp(edge c,edge d){
return c.y<d.y;
}
int main(){
cin>>n>>s>>a>>b;
for(int i=1;i<=n;i++)cin>>e[i].x>>e[i].y;
sort(e+1,e+n+1,cmp);
for(int i=1;i<=n;i++){
if(s-e[i].y<=0)break;
if(a+b>=e[i].y){
s-=e[i].y;
ans++;
}
}
cout<<ans;
return 0;
}
by 枫原万叶 @ 2024-07-31 11:02:49
@WJR2023
#include <bits/stdc++.h>
using namespace std;
int n, s, a, b, ans;
struct edge {
int x, y;
} e[5005];
bool cmp(edge c, edge d) {
return c.y < d.y;
}
int main() {
cin >> n >> s >> a >> b;
for (int i = 1; i <= n; i++)
cin >> e[i].x >> e[i].y;
sort(e + 1, e + n + 1, cmp);
for (int i = 1; i <= n; i++) {
if (s - e[i].y < 0)
break;
if (a + b >= e[i].x) {
s -= e[i].y;
ans++;
}
}
cout << ans;
return 0;
}
by soul2024 @ 2024-07-31 11:12:45
@luogu_cyx thank you