#K49897. Minimum Total Weight of Festival Stones

    ID: 28744 Type: Default 1000ms 256MiB

Minimum Total Weight of Festival Stones

Minimum Total Weight of Festival Stones

In AlgoTown, a festival is celebrated over N days. On the i-th day, some stones are required, given by an array a of length N, where a[i] denotes the number of stones needed on day i.

The town has M types of stones available where each stone type has a specific weight provided in the array weights. To minimize the total weight carried over the festival, the optimal strategy is to use the lightest stone available for every day.

Formally, if we denote the minimum weight as \( w_{min} = \min \{weights\} \) and the total stones needed as \( T = \sum_{i=1}^{N} a[i] \), then the minimum total weight is given by:

\( TotalWeight = T \times w_{min} \)

Your task is to calculate this minimum total weight.

inputFormat

The input consists of three lines:

  1. The first line contains two integers N and M separated by a space, where N is the number of festival days and M is the number of stone types.
  2. The second line contains N positive integers, representing the array a, where each integer is the number of stones required on that day.
  3. The third line contains M positive integers, representing the array weights where each integer is the weight of a stone type.

outputFormat

Output a single integer representing the minimum total weight of stones required over all festival days.

## sample
5 3
4 6 5 8 7
2 3 1
30