atcoder#ARC125E. [ARC125E] Snack

[ARC125E] Snack

Score : 800800 points

Problem Statement

There are NN kinds of snacks numbered 11 through NN. We have AiA_i pieces of Snack ii.

There are MM children numbered 11 through MM. We will distribute the pieces of snacks to these children. Here, all of the following conditions must be satisfied.

  • For every kind of snack, Child ii gets at most BiB_i pieces of that kind.
  • Child ii gets at most CiC_i pieces of snacks in total.

Find the maximum total number of pieces of snacks that can be distributed to the children under these conditions.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1M2×1051 \leq M \leq 2 \times 10^5
  • 1Ai10121 \leq A_i \leq 10^{12}
  • 1Bi1071 \leq B_i \leq 10^7
  • 1Ci10121 \leq C_i \leq 10^{12}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 A2A_2 \cdots ANA_N

B1B_1 B2B_2 \cdots BMB_M

C1C_1 C2C_2 \cdots CMC_M

Output

Print the answer.

3 3
2 5 5
1 2 2
5 3 5
11

The optimal distribution of snacks is as follows.

  • Child 11 gets 11, 11, 11 piece of Snacks 11, 22, 33, respectively.
  • Child 22 gets 00, 22, 11 piece(s) of Snacks 11, 22, 33, respectively.
  • Child 33 gets 11, 22, 22 piece(s) of Snacks 11, 22, 33, respectively.
10 6
3 54 62 64 25 89 1 47 77 4
1 17 10 29 95 17
32 40 90 27 50 9
211