容器、高度与两个版本(简单版)AI (CI翻译)
This is the easy version of the problem. The difference between the versions is that in this version, constraints on $n$ and on the number of test cases are smaller. You can hack only if you solved all versions of this problem.
这是本题的简单版本。与其他版本的区别在于,本版本中 $n$ 和测试用例数量的约束更小。只有在解决了本题的所有版本后才能进行 hack。AI (CI翻译)
There are $n$ communicating vessels of infinite height arranged in a circle. The base area of each vessel is $1$ cm$^2$, and between the $i$-th vessel and the $(i \bmod n) + 1$-th vessel there is a connection of negligible volume at height $h_i$ cm. For each vessel $i$, find the maximum total volume of water in cm$^3$ that can be placed in these vessels under the condition that the $i$-th vessel remains empty.
有 $n$ 个无限高的连通容器,排列成一个圆。每个容器的底面积为 $1$ cm$^2$,第 $i$ 个容器与第 $(i \bmod n) + 1$ 个容器之间,在高度 $h_i$ cm 处有一个体积可忽略不计的连接。对于每个容器 $i$,求在保证第 $i$ 个容器为空的条件下,可以放入这些容器中的水的最大总体积(单位:cm$^3$)。AI (CI翻译)
Formally, you are given an array $h_1, h_2, \ldots, h_n$. A cyclic array of non-negative integers $w_1, w_2, \ldots, w_n$ is called good if the following holds:
形式化地,给定一个数组 $h_1, h_2, \ldots, h_n$。如果一个由非负整数组成的循环数组 $w_1, w_2, \ldots, w_n$ 满足以下条件,则称其为合法数组:AI (CI翻译)
- For every
$i$from$1$to$n$, if$\max(w_i, w_{i \bmod n + 1}) \gt h_i$, then$w_i = w_{i \bmod n + 1}$. In other words, if the maximum of two neighboring elements of the array$w$exceeds the corresponding element of the array$h$, then these two neighboring elements of the array$w$must be equal.
- 对于从
$1$到$n$的每个$i$,如果$\max(w_i, w_{i \bmod n + 1}) \gt h_i$,那么$w_i = w_{i \bmod n + 1}$。换句话说,如果数组$w$中两个相邻元素的最大值超过数组$h$中对应的元素,那么这两个相邻元素必须相等。
For each $i$ from $1$ to $n$, output the maximum possible sum $w_1 + w_2 + \ldots + w_n$ among all good arrays $w_1, w_2, \ldots, w_n$, under the condition that $w_i = 0$.
对于从 $1$ 到 $n$ 的每个 $i$,在满足 $w_i = 0$ 的条件下,输出所有合法数组 $w_1, w_2, \ldots, w_n$ 中 $w_1 + w_2 + \ldots + w_n$ 的最大值。AI (CI翻译)
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.
每个测试包含多个测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 1000$)。接下来是各个测试用例的描述。AI (CI翻译)
The first line of each test case contains one integer $n$ ($3 \le n \le 3000$) — the number of vessels.
每个测试用例的第一行包含一个整数 $n$($3 \le n \le 3000$),表示容器的数量。AI (CI翻译)
The second line of each test case contains $n$ integers $h_1, h_2, \ldots, h_n$ ($1 \le h_i \le 10^9$) — the heights of the partitions between the vessels.
每个测试用例的第二行包含 $n$ 个整数 $h_1, h_2, \ldots, h_n$($1 \le h_i \le 10^9$),表示容器之间隔板的高度。AI (CI翻译)
It is guaranteed that the sum of $n$ over all test cases does not exceed $3000$.
保证所有测试用例的 $n$ 之和不超过 $3000$。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, output $n$ integers — the $l$-th integer means the maximum total volume of water in cm$^3$ in the vessels under the condition that the $l$-th vessel remains empty.
对于每个测试用例,输出 $n$ 个整数——第 $l$ 个整数表示在保证第 $l$ 个容器为空的条件下,容器中水的最大总体积(单位:cm$^3$)。AI (CI翻译)
Note
说明
AI (CI翻译)Consider the first test case.
考虑第一个测试用例。AI (CI翻译)
- To keep vessel
$1$empty, one good array is$w = [0, 1, 2, 3]$, with a total of$6$cm$^3$of water. - To keep vessel
$2$empty, one good array is$w = [1, 0, 2, 3]$, with a total of$6$cm$^3$of water. - To keep vessel
$3$empty, one good array is$w = [2, 2, 0, 3]$, with a total of$7$cm$^3$of water. - To keep vessel
$4$empty, one good array is$w = [3, 3, 3, 0]$, with a total of$9$cm$^3$of water.
- 为使容器
$1$为空,一个合法数组为$w = [0, 1, 2, 3]$,水的总体积为$6$cm$^3$。 - 为使容器
$2$为空,一个合法数组为$w = [1, 0, 2, 3]$,水的总体积为$6$cm$^3$。 - 为使容器
$3$为空,一个合法数组为$w = [2, 2, 0, 3]$,水的总体积为$7$cm$^3$。 - 为使容器
$4$为空,一个合法数组为$w = [3, 3, 3, 0]$,水的总体积为$9$cm$^3$。
For example, the array $w = [2, 2, 0, 4]$ is not good, because $\max(w_3, w_4) \gt h_3$, and therefore $w_3 = w_4$ must hold.
例如,数组 $w = [2, 2, 0, 4]$ 不合法,因为 $\max(w_3, w_4) \gt h_3$,因此必须满足 $w_3 = w_4$。AI (CI翻译)
It can be shown that each of the arrays above has the maximum possible sum among all suitable options.
可以证明,上述每个数组在所有符合条件的方案中都具有最大可能的元素和。AI (CI翻译)
样例
4
4
1 2 3 4
5
5 3 1 5 2
6
3 4 2 6 1 5
7
1 2 1 4 2 3 5
6 6 7 9
17 16 14 14 17
21 21 20 20 21 21
17 17 17 17 21 21 22
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。