#ABC4105. Battles in a Row
Battles in a Row
No testdata at current.
E - Battles in a Row
Problem Statement
Takahashi is about to play a game where he fights N monsters in order. Initially, Takahashi's health is H and his magic power is M.
For the i-th monster he fights, he can choose one of the following actions:
Fight without using magic. This can only be chosen when his health is at least , and his health decreases by and the monster is defeated. Fight using magic. This can only be chosen when his magic power is at least , and his magic power decreases by and the monster is defeated. The game ends when all N monsters are defeated or when he cannot take any action. What is the maximum number of monsters he can defeat before the game ends?
Constraints
All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Output the answer.
Sample Input 1
4 10 14
5 8
5 6
7 9
99 99
Sample Output 1
3
By taking the following actions, Takahashi can defeat 3 monsters before the game ends.
Initially, his health is 10 and his magic power is 14. Fight the 1st monster without using magic. His health decreases by 5, becoming health 5 and magic power 14. Fight the 2nd monster without using magic. His health decreases by 5, becoming health 0 and magic power 14. Fight the 3rd monster using magic. His magic power decreases by 9, becoming health 0 and magic power 5. For the 4th monster, he cannot choose either action, so the game ends.
Sample Input 2
3 3000 3000
3 3
3 3
3 3
Sample Output 2
3
He may be able to defeat all monsters.
Sample Input 3
10 8 8
2 2
2 3
2 2
1 2
2 3
1 2
3 3
3 2
3 1
3 2
Sample Output 3
9