Toyota Programming Contest 2023 Spring Qual B(AtCoder Beginner Contest 290)
Ex
Bow Meow Optimization
AtCoder
⌀ 3569
原题
←G →
翻译中…

Problem Statement

翻译中…

There are $N$ dogs numbered $1$ through $N$ and $M$ cats numbered $1$ through $M$. You will arrange the $(N+M)$ animals in a line from left to right. An arrangement causes each animal's frustration as follows:

翻译中…
  • The frustration of dog $i$ is $A_i\times|x-y|$, where $x$ and $y$ are the numbers of cats to the left and right of that dog, respectively.
  • The frustration of cat $i$ is $B_i\times|x-y|$, where $x$ and $y$ are the numbers of dogs to the left and right of that cat, respectively.
翻译中…

Find the minimum possible sum of the frustrations.

翻译中…

Constraints

翻译中…
  • $1\leq N,M \leq 300$
  • $1\leq A_i,B_i \leq 10^9$
  • All values in the input are integers.
翻译中…

Input

翻译中…

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

翻译中…

N M
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

翻译中…

Output

翻译中…

Print the answer as an integer.

翻译中…

样例

Input #1
2 2
1 3
2 4
Output #1
6
Consider the following arrangement: dog $1$, cat $2$, dog $2$, cat $1$, from left to right. Then, - dog $1$'s frustration is $1\times|0-2|=2$; - dog $2$'s frustration is $3\times|1-1|=0$; - cat $1$'s frustration is $2\times|2-0|=4$; and - cat $2$'s frustration is $4\times|1-1|=0$, so the sum of the frustrations is $6$. Rearranging the animals does not make the sum less than $6$, so the answer is $6$.
Input #2
1 2
100
100 290
Output #2
390
Input #3
5 7
522 575 426 445 772
81 447 629 497 202 775 325
Output #3
13354
题目信息
题号
abc290_h
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。