60分求助

P1478 陶陶摘苹果(升级版)

将cmp函数改为 ```c bool cmp(taotao x,taotao y){ return x.y<y.y; } ```
by A6n6d6y6 @ 2023-05-27 21:00:48


过了!谢谢大佬!!!
by 114514_10086 @ 2023-05-27 21:13:28


``` #include<bits/stdc++.h> using namespace std; struct No { int x; int y; }; bool Nog(No c,No d) { return c.y<d.y; } int main() { int n,s,a,b,sum=0; cin>>n>>s>>a>>b; int m=a+b; No ar[n]; for(int i=0; i<n; i++) { cin>>ar[i].x>>ar[i].y; } sort(ar,ar+n,Nog); for(int i=0; i<n; i++) { if(ar[i].x<=m&&ar[i].y<=s) { s-=ar[i].y; sum++; } } cout<<sum; return 0; } ```
by jiangjinke @ 2023-06-14 16:48:52


|