大神们,这是个排序题啊……

P1478 陶陶摘苹果(升级版)

THESIXGODS @ 2017-10-26 15:07:35

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<queue>
#include<list>
#include<map>
#include<set>
#define ll long long
//#define Maxx ##
using namespace std;
//priority_queue(ll,vector<ll>,greater<ll>)dui;
//queue<ll>q;
//vector<ll>f;
struct re
{
    int h,p;
}xrsb[100010];
inline int read()
{
    int X=0,w=1; char ch=0;
    while(ch<'0' || ch>'9') {if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0' && ch<='9') X=(X<<3)+(X<<1)+ch-'0',ch=getchar();
    return X*w;
}
bool cmp(re x,re y)//升序
{
    return x.p<y.p;
}
int main()
{
    int n;
    int s;
    n=read();
    s=read();
    int a, b;
    a=read();
    b=read();
    int x,y;
    int p=0;
    for(int i=1;i<=n;i++)
    {
        x=read(),y=read();
        if(x<=(a+b))
        {
            p++;
            xrsb[p].h=x;
            xrsb[p].p=y;
        }
    }
    sort(xrsb+1,xrsb+p+1,cmp);
    int app=0;
    int st=0;
    while(s-xrsb[st+1].p>=0&&app+1<p)
    {
        st++;
        s-=xrsb[st].p;
        app++;
    }
    cout<<app;
}

|