Title Description
Another autumn, the Tautau apple tree has a fruit of n. Tata again ran to pick apples, this time she has a a-centimeter chair. When his hand is out of reach, he will stand on the chair and try again.
This time with the NOIp2005 popularization group first problem is different: Tata before moving stool, strength only left S. Of course, every time you pick an apple, you have to use a certain amount of effort. Tata want to know how many apples can be picked up before s<0.
Now known n apples to reach the height of the ground XI, chair height A, Tata hand straighten the maximum length B, Tata's remaining strength S, Tata pick an apple need the strength Yi, beg Tata can pick how many apples.
Input/output format
Input format:
Line 1th: Two number of apples N, strength s.
Line 2nd: The height of the two-digit chair A, Tata the maximum length of the hand straight B.
Line 3rd ~ Line 3+n-1: Two apples per row, Apple height XI, pick the strength that the Apple needs Yi.
Output format:
There is only one integer that represents the maximum number of apples the Tata can pick.
Input and Output Sample input example # #:
8 1520 130120 3150 2110 7180 150 8200 0140 3120 2
Sample # # of output:
4
Description
All data: n<=5000 a<=50 b<=200 s<=1000
xi<=280 yi<=100
代码实现:
1#include <cstdio>2#include <algorithm>3 using namespacestd;4 intN,m,s,a,b,c,ans;5 intw[30000];6 intMain () {7scanf"%d%d%d%d",&n,&s,&a,&b);8a+=b;9 for(intI=1; i<=n;i++){Tenscanf"%d%d",&b,&c); One if(b<=a) w[++m]=C; A } -Sort (w+1, w+m+1); - for(intI=1; i<=m;i++){ the if(W[i]>s) Break; -s-=w[i];++ans; - } -printf"%d\n", ans); + return 0; -}
Judgment + sort + greedy.
Tata Pick Apples (upgrade version)