#P9833. [USACO05OPEN] Expedition G

[USACO05OPEN] Expedition G

Problem Description

A group of cows hijacked a truck and decided to go exploring in the woods. However, their driving skills were so bad that they damaged the fuel tank on the way, so the truck leaks 11 unit of fuel for every 11 unit of distance it travels.

To repair the fuel tank, the cows must reach the nearest city (no more than 10610^6 units of distance away).
Between the current position and the city, there are nn gas stations. The cows can refuel 11 to 100100 units of fuel at a gas station.

For humans, the woods are dangerous; for cows, even more so. Therefore, the cows want to stop for fuel as few times as possible. Luckily, the truck's fuel tank is very large, and you can assume its capacity is infinite.
When the truck is ll units away from the city, it still has pp units of fuel left. You need to find the minimum number of stops needed for the cows to reach the city, or determine that they cannot reach the city at all.

Input Format

The first line contains an integer nn.

Lines 22 to n+1n+1 each contain two integers separated by a space, describing a gas station. The first number is the distance of this gas station from the city, and the second number is the maximum amount of fuel that can be added at this station.

Line n+2n+2 contains two integers ll and pp separated by a space.

Output Format

Output an integer representing the minimum number of stops the truck needs to make to reach the city. If it is impossible to reach, output -1.

4
4 4
5 2
11 5
15 10
25 10

2

Hint

For 100%100\% of the testdata, 1n1041\leq n\leq 10^4 and 1p10000001\leq p\leq 1000000.

Translated by ChatGPT 5