AT_abc459_f.-1, +1

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a sequence of non-negative integers A=(A1,A2,…,AN)A = (A_1, A_2, \ldots, A_N) of length NN.

You can perform the following operation on AA zero or more times:

  • Choose an integer ii with 1≤i≤N−11 \le i \le N - 1, decrease AiA_i by 11, and increase Ai+1A_{i+1} by 11.

Find the minimum number of operations required to make AA strictly increasing.

It can be proved that the answer is less than 2632^{63}.

You are given TT test cases; solve each.

给你一个长度为 NN 的非负整数序列 A=(A1,A2,…,AN)A = (A_1, A_2, \ldots, A_N)。

你可以对 AA 执行以下操作零次或多次:

  • 选择一个满足 1≤i≤N−11 \le i \le N - 1 的整数 ii,将 AiA_i 减少 11,同时将 Ai+1A_{i+1} 增加 11。

求使 AA 严格递增所需的最少操作次数。

可以证明答案小于 2632^{63}。

你将得到 TT 组测试用例,请对每组进行求解。

输入格式

The input is given from Standard Input in the following format:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

The ii-th (1≤i≤T)(1 \le i \le T) test case casei\text{case}_i is given in the following format:

NN
A1A_1 A2A_2 …\ldots ANA_N

输入从标准输入中按以下格式给出:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

第 ii 个 (1≤i≤T)(1 \le i \le T) 测试用例 casei\text{case}_i 按以下格式给出:

NN
A1A_1 A2A_2 …\ldots ANA_N

输出格式

Output the answers for the test cases in order, separated by newlines.

按顺序输出测试用例的答案,答案之间用换行符分隔。

输入输出样例

  • 输入#1

    4
    3
    0 1 0
    4
    4 6 3 5
    7
    1 2 3 4 5 6 7
    10
    11 9 1 3 17 19 10 19 17 3

    输出#1

    3
    5
    0
    78

说明/提示

Sample 1 Explanation:
Consider the first test case.

By performing the following operations, AA can be made strictly increasing in three operations:

  • Choose i=1i=1. AA becomes (−1,2,0)(-1, 2, 0).
  • Choose i=2i=2. AA becomes (−1,1,1)(-1, 1, 1).
  • Choose i=2i=2. AA becomes (−1,0,2)(-1, 0, 2).

It is impossible to make AA strictly increasing in fewer than three operations, so output 33.

Constraints

  • 1≤T≤3×1051 \le T \le 3 \times 10^5
  • 1≤N≤2×1051 \le N \le 2 \times 10^5
  • 0≤Ai≤1090 \le A_i \le 10^9
  • The sum of NN across all test cases is at most 6×1056 \times 10^5.
  • All input values are integers.

样例 1 解释:
考虑第一个测试用例。

通过执行以下操作,可在三次操作内使 AA 严格递增:

  • 选择 i=1i=1,AA 变为 (−1,2,0)(-1, 2, 0);
  • 选择 i=2i=2,AA 变为 (−1,1,1)(-1, 1, 1);
  • 选择 i=2i=2,AA 变为 (−1,0,2)(-1, 0, 2)。

无法用少于三次操作使 AA 严格递增,因此输出 33。

约束条件

  • 1≤T≤3×1051 \le T \le 3 \times 10^5
  • 1≤N≤2×1051 \le N \le 2 \times 10^5
  • 0≤Ai≤1090 \le A_i \le 10^9
  • 所有测试用例的 NN 之和不超过 6×1056 \times 10^5。
  • 所有输入值均为整数。

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

首页