求修正

P1478 陶陶摘苹果(升级版)

wczxluo @ 2023-08-14 16:00:03

#include<bits/stdc++.h>
using namespace std;
struct qwe
{
    int q,w;
}a[10001];
bool comp(qwe x,qwe y)
{
    x.w<y.w;
}
int main()
{
    int n,m,e,r;
    int num=0;
    int ans=0;
    cin>>n>>m;
    cin>>e>>r;
    num=e+r;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].q>>a[i].w;
    }
    sort(a+1,a+1+n,comp);
    for(int i=1;i<=n;i++)
    {
        if(m>=a[i].w&&num>=a[i].q)
        {
            ans++;
            m-=a[i].w;
        }
    }
    cout<<ans;
    return 0;
}

by cat_YIN @ 2023-08-17 09:03:35

没m的dog连这都不会做

#include<bits/stdc++.h>
#define f(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long ll;
ll n,m,num,sum,ans,q,w;
struct apple
{
    ll gao,li;
}a[5005];
bool comp(apple x,apple y)
{
    if(x.li!=y.li) return x.li<y.li;
    else return x.gao<y.gao;
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    cin>>q>>w;
    w+=q;
    f(i,1,n) cin>>a[i].gao>>a[i].li;
    sort(a+1,a+1+n,comp);
    //f(i,1,n) cout<<a[i].gao<<' '<<a[i].li<<endl;
    f(i,1,n)
    {
        if(a[i].gao<=w&&m-a[i].li>=0)
        {
            ans++;
            m-=a[i].li;
        }
        else if(m-a[i].li<0) break;
    }
    cout<<ans;
    return 0;
} 

小狗万岁


|