CF1623C.Balanced Stone Heaps

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn heaps of stone. The ii-th heap has hih_i stones. You want to change the number of stones in the heap by performing the following process once:

  • You go through the heaps from the 33-rd heap to the nn-th heap, in this order.
  • Let ii be the number of the current heap.
  • You can choose a number dd (0≤3⋅d≤hi0 \le 3 \cdot d \le h_i), move dd stones from the ii-th heap to the (i−1)(i - 1)-th heap, and 2⋅d2 \cdot d stones from the ii-th heap to the (i−2)(i - 2)-th heap.
  • So after that hih_i is decreased by 3⋅d3 \cdot d, hi−1h_{i - 1} is increased by dd, and hi−2h_{i - 2} is increased by 2⋅d2 \cdot d.
  • You can choose different or same dd for different operations. Some heaps may become empty, but they still count as heaps.

What is the maximum number of stones in the smallest heap after the process?

有 nn 堆石子。第 ii 堆有 hih_i 颗石子。你希望通过对石子堆执行恰好一次如下过程,来改变各堆石子的数量:

  • 你按顺序依次遍历从第 33 堆到第 nn 堆;
  • 设当前处理的是第 ii 堆;
  • 你可以选择一个整数 dd(满足 0≤3⋅d≤hi0 \le 3 \cdot d \le h_i),将 dd 颗石子从第 ii 堆移至第 (i−1)(i - 1) 堆,并将 2⋅d2 \cdot d 颗石子从第 ii 堆移至第 (i−2)(i - 2) 堆;
  • 因此操作后,hih_i 减少 3⋅d3 \cdot d,hi−1h_{i - 1} 增加 dd,hi−2h_{i - 2} 增加 2⋅d2 \cdot d;
  • 对不同堆的操作,可选择相同或不同的 dd 值;某些堆可能变为零颗石子,但仍视为有效石子堆。

问:经过该过程后,所有堆中最小堆的石子数量的最大可能值是多少?

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤2⋅1051 \le t \le 2\cdot 10^5). Description of the test cases follows.

The first line of each test case contains a single integer nn (3≤n≤2⋅1053 \le n \le 2 \cdot 10^5).

The second lines of each test case contains nn integers h1,h2,h3,…,hnh_1, h_2, h_3, \ldots, h_n (1≤hi≤1091 \le h_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤2⋅1051 \le t \le 2\cdot 10^5)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(3≤n≤2⋅1053 \le n \le 2 \cdot 10^5)。

每个测试用例的第二行包含 nn 个整数 h1,h2,h3,…,hnh_1, h_2, h_3, \ldots, h_n(1≤hi≤1091 \le h_i \le 10^9)。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print the maximum number of stones that the smallest heap can contain.

对于每个测试用例,输出最小堆中所能包含的石头的最大数量。

输入输出样例

  • 输入#1

    4
    4
    1 2 10 100
    4
    100 100 100 1
    5
    5 1 1 1 8
    6
    1 2 3 4 5 6

    输出#1

    7
    1
    1
    3

说明/提示

In the first test case, the initial heap sizes are [1,2,10,100][1, 2, 10, 100]. We can move the stones as follows.

  • move 33 stones and 66 from the 33-rd heap to the 22-nd and 11 heap respectively. The heap sizes will be [7,5,1,100][7, 5, 1, 100];
  • move 66 stones and 1212 stones from the last heap to the 33-rd and 22-nd heap respectively. The heap sizes will be [7,17,7,82][7, 17, 7, 82].

In the second test case, the last heap is 11, and we can not increase its size.

In the third test case, it is better not to move any stones.

In the last test case, the final achievable configuration of the heaps can be [3,5,3,4,3,3][3, 5, 3, 4, 3, 3].

在第一个测试用例中,初始堆的石子数量为 [1,2,10,100][1, 2, 10, 100]。我们可以按如下方式移动石子:

  • 将第 33 堆中的 33 颗石子移至第 22 堆,再将其中 66 颗石子移至第 11 堆。堆的石子数量变为 [7,5,1,100][7, 5, 1, 100];
  • 将最后一堆(即第 44 堆)中的 66 颗石子移至第 33 堆,再将其中 1212 颗石子移至第 22 堆。堆的石子数量变为 [7,17,7,82][7, 17, 7, 82]。

在第二个测试用例中,最后一堆的石子数为 11,我们无法增大其大小。

在第三个测试用例中,最优策略是不移动任何石子。

在最后一个测试用例中,堆所能达到的最终状态可以是 [3,5,3,4,3,3][3, 5, 3, 4, 3, 3]。

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

首页