QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 10

#6070. Panorama Bajhattanu [B]

统计

Bajtłomiej 即将迎来他人生中第一次跨洋旅行,前往 Bajtocja 合众国。他非常想看看 Bajhattan,那里一个巨大城市的一个区。在 Bajhattan 有很多高楼大厦。它的全景图,也就是从远处看建筑物的景象,非常有名。

Bajhattan 由 $n \times m$ 个街区组成。每个街区要么是空的,要么被一座有一定高度的摩天大楼占据。为了简化,我们将空街区等同于被高度为 $0$ 的摩天大楼占据的街区。我们还忽略了街区之间的街道。例如,对于 $n = 3$,$m = 4$ 以及下表中所示的摩天大楼高度(鸟瞰图,表格上方为北)

1 2 0 3
1 0 1 2
2 1 0 1

Bajhattan 如下图所示:

problem_6070_4.gif

Bajtłomiej 只在照片上见过 Bajhattan。最著名的是两张全景图,西向和南向。在示例中,西向全景图中突出的摩天大楼高度分别为 3、2 和 2,而南向全景图中突出的摩天大楼高度分别为 2、2、1 和 3。照片是从很远的地方拍摄的,所以只能看到建筑物的轮廓。

对于示例中的摩天大楼布局,西向全景图如下所示:

problem_6070_2.gif

这是南向全景图:

problem_6070_3.gif

Bajtłomiej 想根据照片确定 Bajhattan 的摩天大楼有多大。他想估算它们的体积(容积)。

请帮助他,并告诉他 Bajhattan 所有摩天大楼可能的最大容积是多少。在示例中,所有摩天大楼的容积为 14,但如果它们的布局略有不同(但全景图保持不变),容积可能高达 22。

输入格式

输入的第一行包含两个整数 $n$ 和 $m$ ($1 \le n, m \le 1\,000\,000$)。下一行包含 $n$ 个整数 $z_{i}$ ($1 \le i \le n$),表示西向全景图中从最北端的摩天大楼开始的各个摩天大楼的高度。第三行包含 $m$ 个整数 $p_{j}$ ($1 \le j \le m$),表示南向全景图中从最西端的摩天大楼开始的各个摩天大楼的高度。你可以假设 $0 \le z_{i}, p_{j} \le 1\,000\,000$。

输出格式

你的程序应该在输出中打印出 Bajhattan 可能的最大容积。如果 Bajtłomiej 搞错了(例如,拿了一张 Bajhattan 的全景图和一张他同样参观的 San Bajcisko 的全景图),并且照片不可能描绘同一个城市,则输出一个单词 NIE

示例

输入

3 4
3 2 2
2 2 1 3

输出

22

输入 2

3 3
0 0 0
2 2 2

输出 2

NIE
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.