#GD0000181. Rồng nhiều đầu (Zmei Gorynich)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Rồng nhiều đầu (Zmei Gorynich)
Zmei Gorynich
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You fight Zmei Gorynich, a dragon initially having heads. There are attack types. Attack cuts off heads when heads currently remain. If at least one head remains after the cut, the dragon immediately regenerates heads. If no heads remain, the dragon is defeated and does not regenerate. You may use any attack type any number of times in any order. Find the minimum number of attacks required, or print -1 if the dragon cannot be defeated.
Input
Line 1 contains two integers and : the number of attack types and the initial number of heads.
Each of the next lines contains two integers and : the number of heads type can cut off and the number that regenerate if the dragon survives.
Output
Print one integer: the minimum number of attacks, or -1 if defeating the dragon is impossible.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Example 1
Input
3 10
6 3
8 2
1 4
Output
2
Explanation
The dragon starts with heads. Attack cuts , leaving , then regenerates , giving . Attack cuts all remaining heads and ends the fight. No attack can cut all initial heads in one blow, so two attacks are optimal.
Example 2
Input
2 15
10 11
14 100
Output
-1
Explanation
Neither attack can kill a dragon with heads immediately. Attack increases the count by while it survives, and increases it even further. The number of heads therefore never decreases enough to permit a finishing attack.