estar_17k @ 2024-03-09 10:48:08
#include<iostream>
#include<algorithm>
using namespace std;
struct pinguo
{
int m,n;
}a[5005];
bool comp(pinguo a,pinguo b){
return a.n>b.n;
}
int main()
{
int shu,li,yizi,shou,x=0;
cin>>shu>>li>>yizi>>shou;
for(int i=0;i<shu;i++)cin>>a[i].m>>a[i].n;
sort(a,a+1,comp);
for(int i=0;i<shu;i++)
if(li>=a[i].n && yizi+shou>=a[i].m){
x++;
li-=a[i].n;
}
cout<<x;
return 0;
}
by estar_17k @ 2024-03-09 10:49:56
在线等,急
by __Rickysun__ @ 2024-03-09 11:16:01
@estar_17k
两个问题:
by __Rickysun__ @ 2024-03-09 11:17:22
@estar_17k 不对,你带代码修改后的
#include<iostream>
#include<algorithm>
using namespace std;
struct pinguo
{
int m,n;
}a[5005];
bool comp(pinguo a,pinguo b){
return a.n<b.n;
}
int main()
{
int shu,li,yizi,shou,x=0;
cin>>shu>>li>>yizi>>shou;
for(int i=0;i<shu;i++)cin>>a[i].m>>a[i].n;
sort(a,a+shu,comp);
for(int i=0;i<shu;i++)
if(li>=a[i].n && yizi+shou>=a[i].m){
x++;
li-=a[i].n;
}
cout<<x;
return 0;
}
不小心把你的错误代码贴上去了
by estar_17k @ 2024-03-09 17:39:43
@Rickysun 谢大佬,已关注!!!