QOJ.ac

QOJ

时间限制: 1 s 内存限制: 32 MB 总分: 100

#12977. 巧克力

统计

给定一块由 $m \times n$ 个小方块组成的巧克力。我们需要将这块巧克力掰成单个的小方块。巧克力可以沿着图中虚线所示的垂直或水平线进行掰开。每次沿着选定的垂直或水平线掰开一块巧克力,都会将其分成两块更小的部分。每次掰开都需要支付一定的费用,费用为一个正整数。该费用与被掰开部分的尺寸无关,仅取决于所沿的线。设沿着连续垂直线掰开的费用为 $x_1, x_2, \dots, x_{m-1}$,沿着水平线掰开的费用为 $y_1, y_2, \dots, y_{n-1}$。将整块巧克力掰成单个小方块的总费用为各次掰开费用之和。请计算将整块巧克力掰成单个小方块所需的最小总费用。

例如,如果我们先沿着水平线掰开巧克力,然后再将得到的每一部分沿着垂直线掰开,那么总费用为 $y_1+y_2+y_3+4 \cdot (x_1+x_2+x_3+x_4+x_5)$。

编写一个程序:

  • 读取数字 $x_1, x_2, \dots, x_{m-1}$ 和 $y_1, y_2, \dots, y_{n-1}$,
  • 计算将整块巧克力掰成单个小方块的最小费用,
  • 输出结果。

输入格式

标准输入的第一行包含两个正整数 $m$ 和 $n$,由一个空格分隔,$2 \le m, n \le 1\,000$。接下来的 $m-1$ 行每行包含一个数字 $x_1, x_2, \dots, x_{m-1}$,每行一个,$1 \le x_i \le 1\,000$。再接下来的 $n-1$ 行每行包含一个数字 $y_1, y_2, \dots, y_{n-1}$,每行一个,$1 \le y_i \le 1\,000$。

输出格式

程序应输出到标准输出。在唯一的一行中,输出一个整数,即掰开整块巧克力所需的最小总费用。

样例

输入 1

6 4
2
1
3
1
4
4
1
2

输出 1

42

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.