Benzinska

면접 대비

시간 제한1초메모리 제한2048 MB

요약
자전거 여행자가 처음 에너지 D를 가지고 X미터를 이동하며 1미터마다 에너지 1을 소모한다. 경로에 있는 식당에서 y_i만큼 에너지를 얻을 수 있을 때, 에너지가 음수가 되지 않도록 최소 몇 곳에서 식당을 이용해야 하는지 구한다.
난이도

보통10점 중 6점

유형
그리디, 힙, 정렬, 누적 합
정답자
아직 제출이 없습니다

문제

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=0x = 0) with an initial energy of DD and wants to reach Čakovec, which is XX meters away from Zagreb (x=Xx = 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 nn restaurants along the way, with the ii-th restaurant located at the x_ix\_i-th meter from the starting point. Multiple restaurants can be located at the same position. If Mr. Malnar decides to dine at the ii-th restaurant, his energy increases by y_iy\_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.

입력

In the first line of input, there are three integers nn, DD, and XX (1≤n≤2⋅1051 ≤ n ≤ 2 \cdot 10^5, 1≤D,X≤1091 ≤ D, X ≤ 10^9), representing the number of restaurants, the initial energy, and the distance between the cities.

In the second line of input, there are nn integers x_ix\_i (1≤x_i<X1 ≤ x\_i < X), representing the positions of the restaurants.

In the third line of input, there are nn integers y_iy\_i (1≤y_i≤1091 ≤ y\_i ≤ 10^9 ), representing the energy Mr. Malnar gains by dining at each respective restaurant.

출력

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).

힌트

Clarification of the first example:

At x=3x = 3, Mr. Malnar will have 22 energy units left. At the first restaurant, he will dine, and his energy will increase to 2+3=52 + 3 = 5. At x=4x = 4, he will have 44 energy units left. At the second restaurant, he will dine, and his energy will increase to 4+2=64 + 2 = 6. At x=8x = 8, he will have 22 energy units left. At the fourth restaurant, he will dine, and his energy will increase to 2+2=42 + 2 = 4. In total, he dined at three restaurants.

예제3

  1. 예제 1

    입력
    5 5 12
    3 4 7 8 11
    3 2 1 2 1
    
    예상 출력
    3
    
  2. 예제 2

    입력
    5 10 40
    1 20 30 2 38
    7 7 7 7 7
    
    예상 출력
    5
    
  3. 예제 3

    입력
    4 5 12
    3 6 9 10
    2 1 2 2
    
    예상 출력
    -1