求救,为何,前四个点都AC了,最后一个点却RE

P1478 陶陶摘苹果(升级版)

vegetablebird4396 @ 2019-11-14 20:33:56

#include<bits/stdc++.h>
using namespace std;
struct apple
{
    int x,y;
}app[6000];

bool com_x(apple a,apple b)   { return a.x<=b.x; }
bool com_y(apple a,apple b)   { return a.y<=b.y; }

int main()
{
    int n,s,a,b;
    cin>>n>>s>>a>>b;
    if(!n) return 0*printf("0");
    for(int i=0;i<n;i++)    cin>>app[i].x>>app[i].y;
    sort(app,app+n,com_x);
    for(int i=0;i<n;i++)    if(app[i].x>a+b) { n=i; break; }
    sort(app,app+n,com_y);
    int i=0;
    do
    {
       s=s-app[i++].y;
    }while(s>=0);
    cout<<i-1;
}

by vzcx_decipher @ 2019-11-14 21:27:21

@vegetablebird4396


by vegetablebird4396 @ 2019-11-14 21:58:30

@Unaccepted_zero

前两行的n,说实话挺鸡肋的,就是前两行的n是因为他是升序排序的,先标记高度第一个高度高于a+b的,然后再排序一遍(被排序部分只有陶陶可以摘得到的苹果,然后从里面最省体力的里面挑),从前往后遍历一遍,就可以了。


by vegetablebird4396 @ 2019-11-14 21:59:37

@Unaccepted_zero

拿去吧,但愿对你有帮助


by vegetablebird4396 @ 2019-11-15 13:23:36

@Unaccepted_zero 我换了个写法就A了,Good Job


上一页 |