#P4823. Dwarfs' Ladder Escape

    ID: 18067 Type: Default 1000ms 256MiB

Dwarfs' Ladder Escape

Dwarfs' Ladder Escape

A group of dwarfs fell into a deep pit. Being too short to climb out on their own, they decided to form a ladder by standing one on another. Specifically, when a dwarf stands on the shoulders of others, the top dwarf can extend his arm to reach the top of the pit and escape.

For each dwarf, you are given his height from foot to shoulder \(A_i\) and his arm length \(B_i\). The depth of the pit is given as \(H\). If using dwarfs 1, 2, 3, \(\ldots\), k as a ladder (in that order), the condition \[ A_1 + A_2 + \cdots + A_k + B_k \ge H \] holds, then the top dwarf (dwarf k) can escape. However, once a dwarf escapes, he cannot help in building another ladder.

Your task is to maximize the number of dwarfs that can escape the pit. Note that the dwarfs who serve as supports (but do not escape) can be reused for building subsequent ladders.

Input Format: The first line contains two integers \(n\) and \(H\), where \(n\) is the number of dwarfs. Each of the following \(n\) lines contains two integers \(A_i\) and \(B_i\) (in that order) for the \(i\)-th dwarf.

Output Format: Output a single integer representing the maximum number of dwarfs that can escape.

inputFormat

The input begins with two space-separated integers \(n\) and \(H\) on a single line.

Then \(n\) lines follow. The \(i\)-th line contains two space-separated integers \(A_i\) and \(B_i\) representing the height from foot to shoulders and the arm length of the \(i\)-th dwarf, respectively.

outputFormat

Output a single integer which is the maximum number of dwarfs that can escape from the pit.

sample

3 10
4 7
5 5
2 3
3