Under construction

Still being built. Things may change

Bodybuilding

Interview

Time limit1sMemory limit512 MB

Summary
Given daily weight gains and minimum weight bounds, find the most routine runs (each losing X kg) that keep his weight above every day's bound.
Level

Easy3 of 10

Topics
Array, Prefix sum
Solved
No attempts yet

Problem

Geonpyo likes working out at the gym and has his own exercise routine. Each time he completes the routine, his body weight drops by XX kg. He can run the routine as many times as he likes in a single day.

Geonpyo prepared a meal plan for the next NN days ahead of a bodybuilding competition. On day ii, the plan adds BiB_i kg to his weight. However, he must not collapse during training, so his final weight on day ii must be at least AiA_i kg. If he trains too much or eats too little so that his final weight on some day is less than AiA_i kg, he collapses on the spot. Geonpyo wants to win the competition, so he wants to run the routine as many times as possible to build the healthiest body he can. Find the maximum number of times he can run the routine without collapsing.

Input

The first line has two integers NN and XX. NN is the number of days left until the competition, and XX is the weight in kg lost each time the routine is run.

The second line has NN integers AiA_i. The ii-th integer AiA_i is the lower bound on his final weight on day ii.

The third line has NN integers BiB_i. The ii-th integer BiB_i is the weight gained on day ii.

Output

Print the maximum number of routine runs Geonpyo can complete without collapsing.

If he collapses within NN days no matter what he does, print -1.

Constraints

  • 1≤N≤500,0001 \leq N \leq 500,000
  • 1≤Ai,Bi,X≤1,000,000,0001 \leq A_i, B_i, X \leq 1,000,000,000 (1≤i≤N1 \leq i \leq N)

Examples2

  1. Example 1

    Input
    10 5
    1 3 2 2 5 7 1 3 1 5
    3 5 6 5 3 1 3 5 1 3
    
    Expected output
    6
    
  2. Example 2

    Input
    1 10
    2
    1
    
    Expected output
    -1