![]() |
||||||||||
|
||||||||||
Save the dwarfsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1633 Accepted Submission(s): 534 Problem Description Several dwarfs are trapped in a deep well. They are not tall enough to climb out of the well, so they want to make a human-pyramid, that is, one dwarf stands on another's shoulder, until the dwarf on the top can reach the top of the well when he raise his arms up. More precisely speaking, we know the i-th dwarf's height from feet to shoulder is Ai, and his arm length Bi. And we know the height of the well is H. If we can build a dwarf-tower consists of dwarf 1, dwarf 2, ..., dwarf k from bottom to top, such that A1 + A2 + ... + Ak-1 + Ak + Bk >= H, then dwarf k can escape from the well. Obviously, the escaped dwarf can't be used to build tower again. We want the escaped dwarfs as many as possible. Please write a program to help the dwarfs. Input The first line of each test case contains N, (1 <= N <= 2000) the number of trapped dwarfs. Each of the following N lines contains two integers Ai and Bi. The last line is H, the height of the well. All the integers are less than 100,000. Output Output one line for each test case, indicating the number of dwarfs escaped at most. Sample Input
Sample Output
Hint For the first case, the tall dwarf can help the other dwarf escape at first. For the second case, only the tall dwarf can escape. Author TJU Source | ||||||||||
|