P1478 陶陶摘蘋果(升級版)
阿新 • • 發佈:2018-12-09
#include<bits/stdc++.h> using namespace std; const int MAXN=5010; struct Node{ int height; int cost; }node[MAXN]; bool cmp(Node a,Node b){ if(a.cost!=b.cost) return a.cost<b.cost; else return a.height<b.height; } int main() { freopen("in.txt","r",stdin); int n,s;cin>>n>>s; int a,b;cin>>a>>b; for(int i=0;i<n;i++){ int h,c;cin>>h>>c; node[i].cost=c;node[i].height=h; } sort(node,node+n,cmp); int l=a+b; int cnt=0; for(int i=0;i<n;i++){ if(s>=node[i].cost&&l>=node[i].height){ cnt++;s-=node[i].cost; } } cout<<cnt; return 0; }