luogu#P4823. [TJOI2013] 拯救小矮人

    ID: 3735 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>贪心2013各省省选排序背包 DP天津

[TJOI2013] 拯救小矮人

Problem Description

A group of dwarfs fell into a very deep pit. Because they are too short to climb out, they decide to build a human ladder. That is, one dwarf stands on another dwarf’s shoulders, until the dwarf at the top can touch the edge of the pit with his arms fully stretched.

For each dwarf, we know his height from feet to shoulders AiA_i, and his arm length BiB_i. The pit depth is HH.

If we use dwarf 11, dwarf 22, dwarf 33, \dots, dwarf kk to build a ladder that satisfies A1+A2+A3++Ak+BkHA_1+A_2+A_3+\dots+A_k+B_k \geq H, then dwarf kk can leave the pit and escape. Once a dwarf escapes, he cannot be used to build the human ladder anymore.

We want as many dwarfs as possible to escape. Find the maximum number of dwarfs that can escape.

Input Format

The first line contains an integer NN, the number of dwarfs. The next NN lines each contain two integers AiA_i and BiB_i. The last line contains HH.

Output Format

Output one integer, the maximum number of dwarfs that can escape.

2
20 10
5 5
30
2
2
20 10
5 5
35
1

Hint

For 30%30\% of the testdata, N200N\leq 200.

For 100%100\% of the testdata, 1N20001 \leq N\leq 2000, 1Ai,Bi,H1051 \leq A_i,B_i,H\leq10^5.

Translated by ChatGPT 5