Rokua-Tata Apple (upgraded version)-boss Battle-Getting started comprehensive Exercise 1

Source: Internet
Author: User

Title DescriptionDescription 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/output 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 sample Input/output sample Test point # # Input Sample:

8 15
20 130
120 3
150 2
110 7
180 1
50 8
200 0
140 3
120 2

Sample output:

4

Idea: The problem is very simple, not explained, easy to understand. O (∩_∩) O (Remember to use global variables).

The code is as follows:

1#include <stdio.h>2 inth[5002],m[5002],i=1, s,n,a,b,j=1, ans; 3 voidKpintLintR)4 {  5     inti=l,j=r,x,t; 6x=m[(I+J)/2]; 7      while(i<=j)8     {  9          while(m[i]<x) i++; Ten          while(X<m[j]) j--;  One         if(i<=j) A         { -t=M[i]; -m[i]=M[j]; them[j]=T; -i++; -j--; -         }   +     }     -     if(l<j) KP (L,J);  +     if(i<R) KP (I,R);  A }    at    - intMain () - {   -scanf"%d%d%d%d",&n,&s,&a,&b);  -      for(i=1; i<=n;i++)   -     { inscanf"%d%d",&h[j],&m[j]); -         if(h[j]<=a+b) to         { +J + +; -         } the     } *j--;  $Kp1, J); Panax Notoginseng      for(i=1; i<=j;i++)   -     { the         if(m[i]<=s) +         { As-=m[i];ans++; the         } +     }   -printf"%d\n", ans);  $     return 0;  $}

Rokua-Tata Apple (upgraded version)-boss Battle-Getting started comprehensive Exercise 1

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.