xinglili @ 2023-07-02 16:31:45
#include<iostream>
#include<algorithm>
using namespace std;
const int N=6e3;
int n,s;
int a,b;
int f[N];//每个水果消耗的力气
int main()
{
cin>>n>>s;
cin>>a>>b;
int cnt=0;
for(int i=0;i<n;i++)
{
int x,y;
cin>>x>>y;
if(x<=a+b)f[cnt++]=y;
}
sort(f,f+cnt);
int ans=0;
while(s>=0)
{
s-=f[ans++];
}
cout<<ans-1;
return 0;
}
by Weizhuo_Zhao @ 2023-07-02 16:44:38
一个黄应该不难,我看看
by A1438329629 @ 2023-07-02 16:49:21
@xinglili 万一淘淘全摘完了呢。。。
#include<iostream>
#include<algorithm>
using namespace std;
const int N=6e3;
int n,s;
int a,b;
int f[N];//每个水果消耗的力气
int main()
{
cin>>n>>s;
cin>>a>>b;
int cnt=0;
for(int i=0;i<n;i++)
{
int x,y;
cin>>x>>y;
if(x<=a+b)f[cnt++]=y;
}
sort(f,f+cnt);
int ans=0;
while(s>=0&&ans<=cnt)
{
s-=f[ans++];
}
cout<<ans-1;
return 0;
}
by xinglili @ 2023-07-02 17:17:54
@A1438329629 懂了,谢谢
by gotocspandbetter @ 2023-08-08 16:36:57
@xinglili 其实第四个点就是4个0 如果按你的代码打的话0-0会一直是0,就结束不了了,所以在前面加一个n=0的特判就可以了。