Problem list
Log in
#coci00693 · COCI 2024/2025 Contest 4

Benzinska

Gold II 1.0 s 512 MB

The camp in Čakovec has already started, but Mr. Malnar is still visiting Zagreb’s restaurants. Wanting to burn the calories he consumed, he decided to cycle to Čakovec. Mr. Malnar starts his journey from Zagreb ($x = 0$) with an initial energy of $D$ and wants to reach Čakovec, which is $X$ meters away from Zagreb ($x = X$). Each meter of the journey requires one unit of energy. To avoid passing out, his energy must not become negative at any point during the trip. There are $n$ restaurants along the way, with the $i$-th restaurant located at the $x_{i}-th$ meter from the starting point. Multiple restaurants can be located at the same position. If Mr. Malnar decides to dine at the $i$-th restaurant, his energy increases by $y_{i}$. He may not eat at the same restaurant multiple times. Help him determine the minimum number of restaurants he must dine at to safely reach Čakovec.

Input

In the first line of input, there are three integers $n$, $D$, and $X$ ($1 \le n \le 2 \cdot 10^{5}$, $1 \le D$, $X \le 10^{9}$), representing the number of restaurants, the initial energy, and the distance between the cities. In the second line of input, there are $n$ integers $x_{i}$ ($1 \le x_{i} < X$), representing the positions of the restaurants. In the third line of input, there are $n$ integers $y_{i}$ ($1 \le y_{i} \le 10^{9}$), representing the energy Mr. Malnar gains by dining at each respective restaurant.

Output

In a single line of output, print the minimum number of restaurants Mr. Malnar must dine at to safely reach Čakovec. If it is not possible to reach Čakovec, print ’-1’ (without quotes).

Example 1

Input
5 5 12
3 4 7 8 11
3 2 1 2 1
Output
3

Example 2

Input
5 10 40
1 20 30 2 38
7 7 7 7 7
Output
5

Example 3

Input
4 5 12
3 6 9 10
2 1 2 2
Output
-1
Source
COCI 2024/2025 Contest 4
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code