Return of the Poop Game
InterviewTime limit0.5sMemory limit1024 MB
Given a start power D and monster and equipment rooms, find the most rooms Gunho can clear before losing to a monster.
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 . There are rooms in front of him. Each room holds either a monster or equipment. The monster or equipment in the -th room () has combat power .
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 and Gunho's starting combat power , separated by a space (, ).
Each of the next lines contains and , separated by a space, describing one room. is 1 if the room has a monster and 2 if it has equipment. () 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...