#abc332g. G - Not Too Many Balls

G - Not Too Many Balls

Score : 625625 points

问题描述

存在若干个球,每个球的颜色为 11, 22, \ldots, NN 中的一种,且对于每个 i=1,2,,Ni = 1, 2, \ldots, N,有 AiA_i 个颜色为 ii 的球。

另外,存在 MM 个盒子。对于每 j=1,2,,Mj = 1, 2, \ldots, M,第 jj 个盒子最多可容纳总共 BjB_j 个球。

在此条件下,对于所有满足 1iN1 \leq i \leq N1jM1 \leq j \leq M 的整数对 (i,j)(i, j),第 jj 个盒子最多可容纳 (i×j)(i \times j) 个颜色为 ii 的球。

请输出这 MM 个盒子最多能容纳的球的总数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are several balls. Each ball is one of the colors 11, 22, \ldots, NN, and for each i=1,2,,Ni = 1, 2, \ldots, N, there are AiA_i balls of color ii.

Additionally, there are MM boxes. For each j=1,2,,Mj = 1, 2, \ldots, M, the jj-th box can hold up to BjB_j balls in total.

Here, for all pairs of integers (i,j)(i, j) satisfying 1iN1 \leq i \leq N and 1jM1 \leq j \leq M, the jj-th box may hold at most (i×j)(i \times j) balls of color ii.

Print the maximum total number of balls that the MM boxes can hold.

Constraints

  • All input values are integers.
  • 1N5001 \leq N \leq 500
  • 1M5×1051 \leq M \leq 5 \times 10^5
  • 0Ai,Bi10120 \leq A_i, B_i \leq 10^{12}

Input

The input is given from Standard Input in the following format:

NN MM

A1A_1 A2A_2 \ldots ANA_N

B1B_1 B2B_2 \ldots BMB_M

Output

Print the answer.

Sample Input 1

2 3
8 10
4 3 8

Sample Output 1

14

You can do as follows to put a total of 1414 balls into the boxes while satisfying the conditions in the problem statement.

  • For balls of color 11, put one into the first box, one into the second box, and three into the third box.
  • For balls of color 22, put two into the first box, two into the second box, and five into the third box.

Sample Input 2

1 1
1000000000000
0

Sample Output 2

0

Sample Input 3

10 12
59 168 130 414 187 236 330 422 31 407
495 218 351 105 351 414 198 230 345 297 489 212

Sample Output 3

2270

update @ 2024/3/10 01:19:06