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) of length N.
You can perform the following operation on A zero or more times:
- Choose an integer i with 1≤i≤N−1, decrease Ai by 1, and increase Ai+1 by 1.
Find the minimum number of operations required to make A strictly increasing.
It can be proved that the answer is less than 263.
You are given T test cases; solve each.
给你一个长度为 N 的非负整数序列 A=(A1,A2,…,AN)。
你可以对 A 执行以下操作零次或多次:
- 选择一个满足 1≤i≤N−1 的整数 i,将 Ai 减少 1,同时将 Ai+1 增加 1。
求使 A 严格递增所需的最少操作次数。
可以证明答案小于 263。
你将得到 T 组测试用例,请对每组进行求解。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
The i-th (1≤i≤T) test case casei is given in the following format:
N
A1 A2 … AN
输入从标准输入中按以下格式给出:
T
case1
case2
⋮
caseT
第 i 个 (1≤i≤T) 测试用例 casei 按以下格式给出:
N
A1 A2 … AN
输出格式
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, A can be made strictly increasing in three operations:
- Choose i=1. A becomes (−1,2,0).
- Choose i=2. A becomes (−1,1,1).
- Choose i=2. A becomes (−1,0,2).
It is impossible to make A strictly increasing in fewer than three operations, so output 3.
Constraints
- 1≤T≤3×105
- 1≤N≤2×105
- 0≤Ai≤109
- The sum of N across all test cases is at most 6×105.
- All input values are integers.
样例 1 解释:
考虑第一个测试用例。
通过执行以下操作,可在三次操作内使 A 严格递增:
- 选择 i=1,A 变为 (−1,2,0);
- 选择 i=2,A 变为 (−1,1,1);
- 选择 i=2,A 变为 (−1,0,2)。
无法用少于三次操作使 A 严格递增,因此输出 3。
约束条件
- 1≤T≤3×105
- 1≤N≤2×105
- 0≤Ai≤109
- 所有测试用例的 N 之和不超过 6×105。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?