20pts求调

P1478 陶陶摘苹果(升级版)

steamdream @ 2024-08-25 11:28:28

rt

代码

#include<bits/stdc++.h>
using namespace std;
const int N=15;
int a[N],b[N],n,s,cnt;
int main()
{
    cin>>n>>s;
    int y,c;
    cin>>y>>c;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
    }
    for(int i=1;i<=10;i++)
    {
        if(a[i]<=c+y&&s>0)
        {
            cnt++;
            s-=b[i];
        }
    }
    cout<<cnt<<endl;
    return 0;
}

by GX_Richard @ 2024-08-25 11:34:25

你要排个序,就先摘消耗体力少的苹果,比如用sort排个序,先扣摘得到且体力消耗最少的苹果


by GX_Richard @ 2024-08-25 11:36:21

@GX_Richard sort不能直接排,可以用struct将a,b数组连起来再排序


by steamdream @ 2024-08-26 18:42:45

谢谢!


|