#P9749. [CSP-J 2023] 公路

[CSP-J 2023] 公路

Problem Description

Xiaobao plans to drive along a highway for a road trip.

There are a total of nn stations on the highway, numbered from 11 to nn. The distance between station ii and station i+1i + 1 is viv_i kilometers.

At every station, you can refuel. At station ii, the price per liter is aia_i yuan, and each station sells only an integer number of liters.

Xiaobao wants to drive from station 11 to station nn. At the beginning, Xiaobao is at station 11 and the fuel tank is empty. It is known that the fuel tank is large enough to hold any amount of fuel, and each liter of fuel allows the car to travel dd kilometers. Find the minimum cost of refueling needed for Xiaobao to drive from station 11 to station nn.

Input Format

The first line contains two positive integers nn and dd, representing the number of stations on the highway and the distance the car can travel per liter of fuel.

The second line contains n1n - 1 positive integers v1,v2vn1v_1, v_2\dots v_{n-1}, representing the distances between adjacent stations.

The third line contains nn positive integers a1,a2ana_1, a_2 \dots a_n, representing the refueling price at each station.

Output Format

Output one line containing only one positive integer, representing the minimum money Xiaobao needs to spend on refueling to drive from station 11 to station nn.

5 4
10 10 10 10
9 8 9 6 5
79

Hint

[Sample 1 Explanation]

In the optimal plan: Xiaobao buys 33 liters at station 11, buys 55 liters at station 22, and buys 22 liters at station 44.

[Sample 2]

See road/road2.in and road/road2.ans under the contestant directory.

[Constraints]

For all testdata, it is guaranteed that: 1n1051 \leq n \leq 10^5, 1d1051 \leq d \leq 10^5, 1vi1051 \leq v_i \leq 10^5, 1ai1051 \leq a_i \leq 10^5.

::cute-table{tuack}

Test Point nn \leq Special Property
151\sim 5 88 None
6106\sim 10 10310^3 ^
111311\sim 13 10510^5 A
141614\sim 16 ^ B
172017\sim 20 None
  • Special Property A: Station 11 has the lowest fuel price.
  • Special Property B: For all 1i<n1 \leq i < n, viv_i is a multiple of dd.

Translated by ChatGPT 5