CF2234C.Vessels, Heights and Two Versions (Easy Version)

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is the easy version of the problem. The difference between the versions is that in this version, constraints on nn and on the number of test cases are smaller. You can hack only if you solved all versions of this problem.

There are nn communicating vessels of infinite height arranged in a circle. The base area of each vessel is 11 cm2^2, and between the ii-th vessel and the (i mod n)+1(i \bmod n) + 1-th vessel there is a connection of negligible volume at height hih_i cm. For each vessel ii, find the maximum total volume of water in cm3^3 that can be placed in these vessels under the condition that the ii-th vessel remains empty.

Formally, you are given an array h1,h2,…,hnh_1, h_2, \ldots, h_n. A cyclic array of non-negative integers w1,w2,…,wnw_1, w_2, \ldots, w_n is called good if the following holds:

  • For every ii from 11 to nn, if max⁡(wi,wi mod n+1)>hi\max(w_i, w_{i \bmod n + 1}) \gt h_i, then wi=wi mod n+1w_i = w_{i \bmod n + 1}. In other words, if the maximum of two neighboring elements of the array ww exceeds the corresponding element of the array hh, then these two neighboring elements of the array ww must be equal.

For each ii from 11 to nn, output the maximum possible sum w1+w2+…+wnw_1 + w_2 + \ldots + w_n among all good arrays w1,w2,…,wnw_1, w_2, \ldots, w_n, under the condition that wi=0w_i = 0.

这是该问题的简单版本。两个版本的区别在于,本版本中对 nn 和测试用例数量的限制更小。只有当你解决了该问题的所有版本后,才可进行 Hack。

有 nn 个无限高的连通容器,呈环形排列。每个容器的底面积均为 1 cm21\ \text{cm}^2,在第 ii 个容器与第 (i mod n)+1(i \bmod n) + 1 个容器之间,于高度 hi cmh_i\ \text{cm} 处存在一个体积可忽略的连通管。对于每个容器 ii,求在保证第 ii 个容器为空的前提下,这些容器中所能容纳的水的最大总体积(单位:cm3\text{cm}^3)。

形式化地,给定一个数组 h1,h2,…,hnh_1, h_2, \ldots, h_n。一个长度为 nn 的非负整数循环数组 w1,w2,…,wnw_1, w_2, \ldots, w_n 称为“合法的”,当且仅当满足以下条件:

  • 对每个 ii(1≤i≤n1 \le i \le n),若 max⁡(wi,wi mod n+1)>hi\max(w_i, w_{i \bmod n + 1}) > h_i,则必有 wi=wi mod n+1w_i = w_{i \bmod n + 1}。换言之,若数组 ww 中相邻两个元素的最大值超过数组 hh 中对应位置的元素,则这两个相邻的 ww 元素必须相等。

对每个 ii(1≤i≤n1 \le i \le n),在约束 wi=0w_i = 0 下,输出所有合法数组 w1,w2,…,wnw_1, w_2, \ldots, w_n 中,和 w1+w2+…+wnw_1 + w_2 + \ldots + w_n 的最大可能值。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10001 \le t \le 1000). The description of the test cases follows.

The first line of each test case contains one integer nn (3≤n≤30003 \le n \le 3000) — the number of vessels.

The second line of each test case contains nn integers h1,h2,…,hnh_1, h_2, \ldots, h_n (1≤hi≤1091 \le h_i \le 10^9) — the heights of the partitions between the vessels.

It is guaranteed that the sum of nn over all test cases does not exceed 30003000.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤10001 \le t \le 1000)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(3≤n≤30003 \le n \le 3000)—— 表示容器的数量。

每个测试用例的第二行包含 nn 个整数 h1,h2,…,hnh_1, h_2, \ldots, h_n(1≤hi≤1091 \le h_i \le 10^9)—— 表示容器之间隔板的高度。

保证所有测试用例的 nn 之和不超过 30003000。

输出格式

For each test case, output nn integers — the ll-th integer means the maximum total volume of water in cm3^3 in the vessels under the condition that the ll-th vessel remains empty.

对于每个测试用例,输出 nn 个整数——其中第 ll 个整数表示在第 ll 个容器保持为空的条件下,所有容器中水的总体积(单位:cm3^3)的最大值。

输入输出样例

  • 输入#1

    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

    输出#1

    6 6 7 9 
    17 16 14 14 17 
    21 21 20 20 21 21 
    17 17 17 17 21 21 22

说明/提示

Consider the first test case.

  • To keep vessel 11 empty, one good array is w=[0,1,2,3]w = [0, 1, 2, 3], with a total of 66 cm3^3 of water.
  • To keep vessel 22 empty, one good array is w=[1,0,2,3]w = [1, 0, 2, 3], with a total of 66 cm3^3 of water.
  • To keep vessel 33 empty, one good array is w=[2,2,0,3]w = [2, 2, 0, 3], with a total of 77 cm3^3 of water.
  • To keep vessel 44 empty, one good array is w=[3,3,3,0]w = [3, 3, 3, 0], with a total of 99 cm3^3 of water.

For example, the array w=[2,2,0,4]w = [2, 2, 0, 4] is not good, because max⁡(w3,w4)>h3\max(w_3, w_4) \gt h_3, and therefore w3=w4w_3 = w_4 must hold.

It can be shown that each of the arrays above has the maximum possible sum among all suitable options.

考虑第一个测试用例。

  • 为使容器 11 保持为空,一个可行的数组是 w=[0,1,2,3]w = [0, 1, 2, 3],总水量为 66 cm3^3。
  • 为使容器 22 保持为空,一个可行的数组是 w=[1,0,2,3]w = [1, 0, 2, 3],总水量为 66 cm3^3。
  • 为使容器 33 保持为空,一个可行的数组是 w=[2,2,0,3]w = [2, 2, 0, 3],总水量为 77 cm3^3。
  • 为使容器 44 保持为空,一个可行的数组是 w=[3,3,3,0]w = [3, 3, 3, 0],总水量为 99 cm3^3。

例如,数组 w=[2,2,0,4]w = [2, 2, 0, 4] 不可行,因为 max⁡(w3,w4)>h3\max(w_3, w_4) \gt h_3,因此必须满足 w3=w4w_3 = w_4。

可以证明,上述每个数组在其各自约束下的所有可行选项中,均具有最大的可能和。

输入解题思路,AI测评打分。不知道怎么写?

首页