QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100

#7810. Highway

الإحصائيات

Xiao Bao is preparing to go on a road trip.

There are $n$ stations on the road, numbered from $1$ to $n$. The distance between station $i$ and station $i+1$ is $v_i$ kilometers.

Every station on the road offers refueling. The price of one liter of fuel at station $i$ is $a_i$ yuan, and each station only sells an integer number of liters of fuel.

Xiao Bao wants to drive from station $1$ to station $n$. Initially, Xiao Bao is at station $1$ and the car's fuel tank is empty. It is known that the car's fuel tank is large enough to hold any amount of fuel, and each liter of fuel allows the car to travel $d$ kilometers. What is the minimum cost for Xiao Bao to refuel to drive from station $1$ to station $n$?

Input

The first line contains two positive integers $n$ and $d$, representing the number of stations on the road and the distance the car can travel per liter of fuel, respectively.

The second line contains $n-1$ positive integers $v_1, v_2, \dots, v_{n-1}$, representing the distances between the stations.

The third line contains $n$ positive integers $a_1, a_2, \dots, a_n$, representing the fuel prices at different stations.

Output

Output a single line containing one integer, representing the minimum cost for Xiao Bao to refuel to drive from station $1$ to station $n$.

Examples

Input 1

5 4
2 10 10 10 10
9 8 9 6 5

Output 1

79

Note 1

In the optimal plan: Xiao Bao buys $3$ liters of fuel at station $1$, $5$ liters of fuel at station $2$, and $2$ liters of fuel at station $4$.

Input 2

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

Constraints

For all test data, it is guaranteed that $1 \le n \le 10^5$, $1 \le d \le 10^5$, $1 \le v_i \le 10^5$, $1 \le a_i \le 10^5$.

Test Cases $n \le$ Special Property
$1 \sim 5$ $8$ None
$6 \sim 10$ $10^3$ None
$11 \sim 13$ $10^5$ A
$14 \sim 16$ $10^5$ B
$17 \sim 20$ $10^5$ None

Special Property A: The fuel price at station $1$ is the lowest.

Special Property B: For all $1 \le i < n$, $v_i$ is a multiple of $d$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.