Oye0ye @ 2023-02-15 16:20:10
#include<bits/stdc++.h>
using namespace std;
int lx[100005];
struct aaa{
int g;
int l;
}oye[100005];
bool cmp(struct aaa i,struct aaa j)
{
return i.l<j.l;
}
int main()
{
int s=0,n,m,a,b;
cin>>n>>m>>a>>b;
for(int i=1;i<=n;i++)
{
cin>>oye[i].g>>oye[i].l;
}
sort(oye+1,oye+n+1,cmp);
for(int i=1;i<=n;i++)
{
if(oye[i].g<=a+b)lx[s++]=i;
}
int s1=1;
s=0;
while(m>0)
{
if(m-lx[s1]<0)break;
m-=lx[s1++];
s++;
}
cout<<s;
}
by Oye0ye @ 2023-02-15 16:21:23
救救孩子
by ncwzdlsd @ 2023-02-15 16:36:49
@oyeoye
#include<bits/stdc++.h>
using namespace std;
int lx[100005];
struct aaa{
int g;
int l;
}oye[100005];
bool cmp(struct aaa i,struct aaa j)
{
// if(i.l!=j.l)
return i.l<j.l;
// return i.g<j.g;
}
int main()
{
int s=0,n,m,a,b;
cin>>n>>m>>a>>b;
for(int i=1;i<=n;i++)
{
cin>>oye[i].g>>oye[i].l;
}
sort(oye+1,oye+n+1,cmp);
for(int i=1;i<=n;i++)
{
if(m>=oye[i].l&&a+b>=oye[i].g) m-=oye[i].l,s++;
if(m<0) break;
}
cout<<s;
return 0;
}
by ncwzdlsd @ 2023-02-15 16:37:43
@oyeoye 感觉您最后累加答案的时候有点儿麻烦了,改了一下理了理逻辑现在过了
by Oye0ye @ 2023-02-15 17:03:09
谢谢大佬