Myosotis_alpestris @ 2023-05-12 20:35:38
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e6+10;
int num,ans;
struct node{
int tall,qi;
}apple[10000000];
bool cmp(node a,node b)
{
if(a.qi==b.qi) return a.tall<b.tall;
return a.qi<b.qi;
}
int main()
{
int n,s;
cin>>n>>s;
int a,b;
cin>>a>>b;
a+=b;
for (int i=1;i<=n;i++)
{
cin>>apple[i].tall>>apple[i].qi;
}
sort(apple+1,apple+n,cmp);
for (int i=1;i<=n;i++)
{
if(apple[i].tall>a) continue;
if(s>=apple[i].qi)
{
s-=apple[i].qi;
}
else
{
break;
}
ans++;
}
cout<<ans<<endl;
return 0;
}
by jimeikun_sunxuhao @ 2023-05-12 21:03:35
但凡多写个+1
还有,数组没必要开这么打,而且这个数组里完全可以写MAXN而不是直接一串数字
by __Tonycyt__ @ 2023-05-12 21:10:36
@jimeikun_sunxuhao 他原本写+1
了啊
by __Tonycyt__ @ 2023-05-12 21:11:20
应该是sort(apple+1,apple+n+1,cmp);
by jimeikun_sunxuhao @ 2023-05-12 21:12:15
@Tonycyt 我的意思就是apple+n应该写成apple+n+1哦....
by __Tonycyt__ @ 2023-05-12 21:13:26
@jimeikun_sunxuhao 可是你应该为那段代码没写+1
……(蒟蒻不计较了)
by jimeikun_sunxuhao @ 2023-05-12 21:15:34
@Tonycyt woc才发现我没打上orz(
by jimeikun_sunxuhao @ 2023-05-12 21:16:16
@jimeikun_sunxuhao
sort(apple+1,apple+n+1,cmp);
by __Tonycyt__ @ 2023-05-12 21:29:39
@jimeikun_sunxuhao 6