求救,80分,最后一个测试点WA,调了快1小时了,救救蒟蒻!

P1478 陶陶摘苹果(升级版)

_wzcxx @ 2021-11-29 21:31:44

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n,s,a,b;
    cin>>n>>s;
    cin>>a>>b;
    int x[1001000],y[1001000];
    for(int i=1;i<=n;i++)    cin>>x[i]>>y[i];
    //sort(x,x+1+n);
    sort(y,y+1+n);
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        if (s>=y[i])
        {
            if (x[i]<=(a+b))
            {
                sum++;
                s-=y[i];
            } 
            else  continue;  
        }
        else  break;
    }
    cout<<sum<<endl;
    return 0;
}

by Y2y7m @ 2021-11-29 21:37:40

x和y没有同时改动,用一个结构体就好了


by Y2y7m @ 2021-11-29 21:39:19

话说,你抄我代码你还问个啥@王梓辰666!


by WYH002 @ 2022-01-05 17:30:29

@Yueyiming hahahahahahahahahahahaha


|