(水题)洛谷 - P1478 - 陶陶摘苹果(升级版)
https://www.luogu.org/problemnew/show/P1478
没啥好说的……
居然还漏写一个等于号WA了一发。
#include<bits/stdc++.h> using namespace std; #define ll long long int n,tn=0,s,a,b; struct apple{ int y; bool operator<(apple that){ return y<that.y; } }app[5005]; int main(){ scanf("%d%d",&n,&s); scanf("%d%d",&a,&b); for(int i=0;i<n;i++){ int tx,ty; scanf("%d%d",&tx,&ty); if(a+b>=tx){ app[tn].y=ty; tn++; } } sort(app,app+tn); int cnt=0; for(int i=0;i<tn;i++){ if(s>=app[i].y){ s-=app[i].y; cnt++; } else{ break; } } printf("%d\n",cnt); }