Tata Pick Apples (upgrade version)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.