Under construction

Still being built. Things may change

Return of the Poop Game

Interview

Time limit0.5sMemory limit1024 MB

Summary
Given a start power D and monster and equipment rooms, find the most rooms Gunho can clear before losing to a monster.
Level

Medium5 of 10

Topics
Greedy, Sorting
Solved
No attempts yet

Problem

Gunho saw too many poop game ads on YouTube, so he decided to install one and play it himself.

Gunho starts with combat power DD. There are NN rooms in front of him. Each room holds either a monster or equipment. The monster or equipment in the ii-th room (1≤i≤N1\leq i\leq N) has combat power XiX_i.

Each time, Gunho can freely choose which room to enter next among the rooms he has not yet cleared. He acts as follows depending on what the room contains.

  • Monster: If Gunho's combat power is greater than the monster's, he can defeat the monster, and then the monster's combat power is added to his. If his combat power is less than or equal to the monster's, he loses.
  • Equipment: He can obtain it regardless of his current combat power, and his combat power is multiplied by the equipment's combat power. However, he can obtain a piece of equipment only after obtaining every piece of equipment with lower combat power than it.

When he defeats a monster or obtains equipment, that room is cleared. The game ends when Gunho clears every room or loses to a monster.

Assuming Gunho plays with the best strategy, find the maximum number of rooms he can clear.

Note that there is no upper limit on the combat power Gunho can reach through his actions.

Input

The first line contains the number of rooms NN and Gunho's starting combat power DD, separated by a space (1≤N≤1000001\leq N\leq 100000, 1≤D≤1091\leq D\leq 10^9).

Each of the next NN lines contains AiA_i and XiX_i, separated by a space, describing one room. AiA_i is 1 if the room has a monster and 2 if it has equipment. XiX_i (2≤Xi≤1092\leq X_i\leq 10^9) is the combat power of the monster or equipment in that room.

Output

On the first line, print the maximum number of rooms Gunho can clear.

Hint

Gunho still has not cleared this poop game...

Examples2

  1. Example 1

    Input
    5 5
    1 2
    1 3
    1 10
    2 2
    1 40
    
    Expected output
    4
    
  2. Example 2

    Input
    8 3
    2 5
    1 4
    1 2
    1 10
    2 7
    1 50
    1 264
    1 999
    
    Expected output
    7