QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB

#23951. 銅鑼燒

Statistics

題目描述

JOI 君打算製作銅鑼燒。

一個銅鑼燒由豆沙餡與餅皮各 $1$ 個製作而成,所有豆沙餡與餅皮都定義了用正整數表示的「美味度」。有從 $1$ 到 $N$ 編號的 $N$ 種豆沙餡,豆沙餡 $i$($1 \le i \le N$)的美味度為 $A_i$。此外,還有從 $1$ 到 $M$ 編號的 $M$ 種餅皮,餅皮 $j$($1 \le j \le M$)的美味度為 $B_j$。

JOI 君會嘗試這些豆沙餡與餅皮的所有組合,製作出 $N \times M$ 個銅鑼燒。每個銅鑼燒的美味度等於豆沙餡與餅皮的美味度之和乘以豆沙餡與餅皮的美味度中的較大值。

求這 $N \times M$ 個銅鑼燒的美味度總和。

限制條件

  • $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$)。
  • 輸入的值均為整數。

輸入

輸入以如下格式給出:
$N$ $M$
$A_1$ $A_2$ $\dots$ $A_N$
$B_1$ $B_2$ $\dots$ $B_M$

輸出

輸出 $N \times M$ 個銅鑼燒的美味度總和。

請不要輸出除答案以外的任何內容。(請不要輸出提示輸入的文字等。)

關於解答格式,也可以參考練習題及其解答範例。


範例輸入 1

2 2
1 2
2 5

範例輸出 1

79

對於製作出的 $4$ 個銅鑼燒,各自的美味度如下:

  • 由豆沙餡 $1$ 和餅皮 $1$ 製作出的銅鑼燒的美味度為:豆沙餡與餅皮的美味度之和 $3 (= 1 + 2)$ 乘以兩者美味度中的較大值 $2$,結果為 $6$。
  • 由豆沙餡 $1$ 和餅皮 $2$ 製作出的銅鑼燒的美味度為:豆沙餡與餅皮的美味度之和 $6 (= 1 + 5)$ 乘以兩者美味度中的較大值 $5$,結果為 $30$。
  • 由豆沙餡 $2$ 和餅皮 $1$ 製作出的銅鑼燒的美味度為:豆沙餡與餅皮的美味度之和 $4 (= 2 + 2)$ 乘以兩者美味度中的較大值 $2$,結果為 $8$。
  • 由豆沙餡 $2$ 和餅皮 $2$ 製作出的銅鑼燒的美味度為:豆沙餡與餅皮的美味度之和 $7 (= 2 + 5)$ 乘以兩者美味度中的較大值 $5$,結果為 $35$。

根據它們的總和,輸出 $79 (= 6 + 30 + 8 + 35)$ 即可。


範例輸入 2

1 5
50
9 7 5 4 1

範例輸出 2

13800

範例輸入 3

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

範例輸出 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.