QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 1024 MB

#23951. Dorayaki

統計

Problem Description

JOI is going to make dorayaki (a Japanese confection).

A dorayaki can be made from a filling and a pancake ($1$ of each), and every filling and pancake has a defined "deliciousness" represented by a positive integer. There are $N$ types of fillings numbered from $1$ to $N$, and the deliciousness of filling $i$ ($1 \le i \le N$) is $A_i$. Also, there are $M$ types of pancakes numbered from $1$ to $M$, and the deliciousness of pancake $j$ ($1 \le j \le M$) is $B_j$.

JOI tries all combinations of these fillings and pancakes to make $N \times M$ dorayaki. The deliciousness of each dorayaki is the sum of the deliciousness of its filling and pancake, multiplied by the larger of the deliciousness of its filling and pancake.

Find the sum of the deliciousness of all $N \times M$ dorayaki.

Constraints

  • $1 \le N \le 100$.
  • $1 \le M \le 100$.
  • $1 \le A_i \le 100$ ($1 \le i \le N$).
  • $1 \le B_j \le 100$ ($1 \le j \le M$).
  • All input values are integers.

Input

The input is given in the following format:
$N$ $M$
$A_1$ $A_2$ $\dots$ $A_N$
$B_1$ $B_2$ $\dots$ $B_M$

Output

Output the sum of the deliciousness of all $N \times M$ dorayaki.

Do not output anything other than the answer. (Do not output prompt messages for input, etc.)

For the answer format, you may also refer to the practice problems and their sample solutions.


Sample Input 1

2 2
1 2
2 5

Sample Output 1

79

For each of the $4$ dorayaki made, the deliciousness is as follows:

  • The deliciousness of the dorayaki made from filling $1$ and pancake $1$ is $6$, which is the sum of the deliciousness of the filling and pancake, $3 (= 1 + 2)$, multiplied by the larger of their deliciousness values, $2$.
  • The deliciousness of the dorayaki made from filling $1$ and pancake $2$ is $30$, which is the sum of the deliciousness of the filling and pancake, $6 (= 1 + 5)$, multiplied by the larger of their deliciousness values, $5$.
  • The deliciousness of the dorayaki made from filling $2$ and pancake $1$ is $8$, which is the sum of the deliciousness of the filling and pancake, $4 (= 2 + 2)$, multiplied by the larger of their deliciousness values, $2$.
  • The deliciousness of the dorayaki made from filling $2$ and pancake $2$ is $35$, which is the sum of the deliciousness of the filling and pancake, $7 (= 2 + 5)$, multiplied by the larger of their deliciousness values, $5$.

From the sum of these values, output $79 (= 6 + 30 + 8 + 35)$.


Sample Input 2

1 5
50
9 7 5 4 1

Sample Output 2

13800

Sample Input 3

15 5
5 10 52 31 14 16 19 1 9 20 80 19 11 34 72
20 2 4 9 19

Sample Output 3

116756

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.