#P3399. 丝绸之路

丝绸之路

Description

A little hamster is delivering goods from China to Baghdad. The Silk Road has N+1N+1 cities including the start and the end. City 00 is the starting point Chang’an, and city NN is the destination Baghdad. The hamster must reach the destination in at most MM days. In one day, it is possible to travel from one city to the next consecutive city. The distance from city i1i-1 to city ii is DiD_i.

As everyone knows, traveling continuously is exhausting, so when staying in a city, the hamster has two choices:

  • Move: set off toward the next city.
  • Rest: stay in the current city without moving.

Desert weather is unpredictable. When the weather is bad, moving forward is much more difficult. Let the severity of the weather on the jj-th day (1jM1 \le j \le M) be CjC_j. If the hamster moves from city i1i-1 to city ii on day jj, it incurs a fatigue of Di×CjD_i \times C_j.

However, the hamster can choose to avoid worse weather; resting consumes no fatigue. Now it wants to know the minimum total fatigue for the whole trip.

Input Format

The first line contains 22 integers NN and MM.

The next NN lines each contain one integer DjD_j.

The next MM lines each contain one integer CjC_j.

Output Format

Output a single integer, the minimal total fatigue.

3 5
10
25
15
50
30
15
40
30
1125

Hint

Sample Explanation

Rest on day 11.

On day 22, 010 \rightarrow 1, fatigue 10×30=30010 \times 30 = 300.

On day 33, 121 \rightarrow 2, fatigue 25×15=37525 \times 15 = 375.

Rest on day 44.

On day 55, 232 \rightarrow 3, fatigue 15×30=45015 \times 30 = 450.

Constraints

1NM10001 \le N \le M \le 1000.

1Di,Ci10001 \le D_i, C_i \le 1000.

Translated by ChatGPT 5