# 2,3,5RE,40分,求助

P1478 陶陶摘苹果(升级版)

NorlandAlice @ 2024-06-14 16:46:56

2,3,5RE,40分,求助

#include<bits/stdc++.h>
using namespace std;

struct k{int x,y;}qq[5008];
bool kk(k c,k d){
if(c.y<d.y)return 1;}
int main(){
int n,s,a,b,sum=0;
cin>>n>>s>>a>>b;
for(int i=0;i<n;i++){cin>>qq[i].x>>qq[i].y;}
sort(qq,qq+n,kk);
for(int i=0;i<n;i++){
if(qq[i].x>a+b)continue;
if(qq[i].x<=a+b){
    if(s>=qq[i].y){sum++;s-=qq[i].y;}
    else break;}}
cout<<sum;
return 0;}

by xixisuper @ 2024-06-14 17:00:39

@NorlandAlice 比较函数 kk 里面缺返回值,不满足 c.y<d.y 的时候应该返回 false


by xixisuper @ 2024-06-14 17:01:55

@NorlandAlice 把 kk 改成这样就过了。

bool kk(k c,k d){
if(c.y<d.y)return 1;
else return 0;}

by NorlandAlice @ 2024-06-14 17:13:35

@xixisuper 谢谢!


|