SN_Tashkent @ 2022-11-09 19:23:39
#include<bits/stdc++.h>
using namespace std;
#define MAXN 5000+15
int n,s,a,b,ans=0;
struct app{
int x;
int y;
}A[MAXN];
bool cmp(app a,app b)
{
return a.y<b.y;
}
int main()
{
cin>>n>>s;
cin>>a>>b;
int j=1;
int taotao=a+b;
for(int i=1;i<=n;i++)
{
cin>>A[i].x;
cin>>A[i].y;
}
sort(A+1,A+n+1,cmp);
while(s-A[j].y>=0)
{
if(A[j].x<=taotao)
{
ans++;
j++;
s-=A[j].y;
}
else
j++;
}
cout<<ans;
return 0;
}
by D3ath @ 2022-12-03 20:08:21
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN 5000+15
int n, s, a, b, ans = 0;
struct app {
int x;
int y;
}A[MAXN];
bool cmp(app a, app b)
{
return a.y < b.y;
}
int main()
{
cin >> n >> s;
cin >> a >> b;
int j = 1;
int taotao = a + b;
for (int i = 1; i <= n; i++)
{
cin >> A[i].x;
cin >> A[i].y;
}
sort(A + 1, A + n + 1, cmp);
while (s- A[j].y >= 0)
{
if (A[j].x <= taotao)
{
ans++;
s -= A[j].y;
j++;
}
else
j++;
}
cout << ans;
return 0;
}