#B3673. Garbage Disposal Optimization in Dream City

    ID: 11332 Type: Default 1000ms 256MiB

Garbage Disposal Optimization in Dream City

Garbage Disposal Optimization in Dream City

In the year 2077, Dream City has implemented a remarkably strict garbage classification system to combat severe resource shortages. There are \(n\) types of garbage, and each type can only be disposed of in its designated bin. Specifically, the first \(n\) bins have restricted capacities defined by a sequence \(r_1, r_2, \dots, r_n\); the \(i\)th bin can only accept garbage of type \(i\) and at most \(r_i\) pieces.

In addition, there is an extra bin labeled \(n+1\) which can accept any type of garbage. However, each piece of garbage deposited in this bin incurs a cost of \(c\). Given a sequence \(a_1, a_2, \dots, a_n\) representing the number of garbage pieces of each type at your home, determine the minimum cost required to dispose of all the garbage.

inputFormat

The first line contains two integers \(n\) and \(c\) --- the number of garbage types and the cost per piece for the extra bin respectively.

The second line contains \(n\) integers \(r_1, r_2, \dots, r_n\), where \(r_i\) denotes the capacity of the \(i\)th bin.

The third line contains \(n\) integers \(a_1, a_2, \dots, a_n\), where \(a_i\) represents the number of pieces of garbage of type \(i\).

outputFormat

Output a single integer representing the minimum total cost required to dispose of all the garbage.

sample

3 10
5 0 3
3 2 3
20