求救,60分,RE+TLE,求大佬指教

P1478 陶陶摘苹果(升级版)

王熙宇 @ 2018-08-12 00:04:23

include<bits/stdc++.h>

using namespace std; long long n,s,a,b,num=0; struct apple { int high,power; }que[1000007]; bool cmp(apple x,apple y) { if(x.power!=y.power) return x.power<y.power; } int main() { //freopen("date.in","r",stdin); //freopen("date.out","w",stdout); cin>>n>>s; cin>>a>>b; for(int i=1;i<=n;i++) cin>>que[i].high>>que[i].power; sort(que+1,que+1+n,cmp); for(int i=1;i<=n;i++) if(a+b>=que[i].high&&s>=que[i].power) { s=s-que[i].power; num++; } cout<<num<<endl; return 0; }


by 王熙宇 @ 2018-08-12 00:07:26

include<bits/stdc++.h>

using namespace std;

long long n,s,a,b,num=0;

struct apple

{

int high,power;

}que[1000007];

bool cmp(apple x,apple y)

{

if(x.power!=y.power)
    return x.power<y.power;

}

int main() {

//freopen("date.in","r",stdin);
//freopen("date.out","w",stdout);
cin>>n>>s;
cin>>a>>b;
for(int i=1;i<=n;i++)
    cin>>que[i].high>>que[i].power;
sort(que+1,que+1+n,cmp);
for(int i=1;i<=n;i++)
    if(a+b>=que[i].high&&s>=que[i].power)
    {
        s=s-que[i].power;
        num++;
    }
cout<<num<<endl;
return 0;

}


by 花园Serena @ 2018-08-12 07:04:37

希望更丰富的展现?使用Markdown


by MessageBoxA @ 2018-08-12 08:01:45

希望更丰富的展现?使用Markdown!


by Zenurik @ 2018-08-12 08:27:46

希望更丰富的展现?使用Markdown!


by Schrodinger @ 2018-08-12 08:27:47

?


by kkksc02 @ 2018-08-12 08:58:47

希望更丰富的展现?使用Markdown!


by kkksc02 @ 2018-08-12 08:59:11

希望更丰富的展现?使用Markdown!

|