Tata Pick Apples (upgrade version)

Source: Internet
Author: User

title Source: http://www.luogu.org/problem/show?pid=1478# " Title DescriptionDescription "Another autumn, the Tautau Apple tree has a n fruit. 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 and 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" "Input Sample:"

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

"Output Example:"
4  "description description"All data: n<=5000 a<=50 b<=200 s<=1000 xi<=280 yi<=100

Ideas

Originally I thought this topic is DP, for Apple to take and not take two kinds of states, like a backpack model, and later found that the transfer equation almost can't write out. Later found that as long as the reading in the time to do a preprocessing, and then quickly charge the physical value, the last accumulator accumulated more than the exit can be. The time complexity is instead on the sort, O (N*logn).

typeapple=RecordX1,y1:longint; End;//xx is the height, yy is the strengthvarAppArray[1.. +] ofApple;    N,s,a,b,xx,yy,i:longint; Sum:longint=0; Sum1:longint=0; Ans:longint=0;proceduresort (l,r:longint); vari,j,x:longint;y:apple; beginI:=l; J:=R; X:=app[(L+r)Div 2].y1; Repeat            whileApp[i].y1<x DoInc (I);  whileX<app[j].y1 DoDec (j); if  not(I&GT;J) Then             beginy:=App[i]; App[i]:=App[j]; APP[J]:=y;                Inc (I); J:=j-1; End; untilI>J; ifL<j Thensort (l,j); ifI<r Thensort (i,r); End;beginreadln (n,s);    Readln (A, b);  fori:=1  toN Do        beginreadln (XX,YY); ifA+b>=xx Then                beginInc (SUM); APP[SUM].X1:=xx; App[sum].y1:=yy; End; End; Sort (1, sum);  fori:=1  toSum Do        beginInc (SUM1,APP[I].Y1); ifSum1<=s ThenInc (ANS)ElseBreak ; End; Writeln (ans);End.

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.