CF2169C.Range Operation
普及-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer array a of length n.
You can perform the following operation: choose a range [l,r] (1≤l≤r≤n) and replace the value of elements al,al+1,…,ar with (l+r).
Your task is to calculate the maximum possible total array sum if you can perform the aforementioned operation at most once.
给你一个长度为 n 的整数数组 a。
你可以执行以下操作:选择一个区间 [l,r](其中 1≤l≤r≤n),并将元素 al,al+1,…,ar 的值全部替换为 (l+r)。
你的任务是:在最多执行一次上述操作的前提下,计算数组总和的最大可能值。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains a single integer n (1≤n≤2⋅105).
The second line contains n integers a1,a2,…,an (0≤ai≤2n).
Additional constraint on the input: the sum of n over all test cases doesn't exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)。
第二行包含 n 个整数 a1,a2,…,an(0≤ai≤2n)。
输入的额外约束:所有测试用例的 n 值之和不超过 2⋅105。
输出格式
For each test case, print a single integer — the maximum possible total array sum if you can perform the aforementioned operation at most once.
对于每个测试用例,输出一个整数——即最多执行一次上述操作时,数组元素总和的最大可能值。
输入输出样例
输入#1
4 3 2 5 1 2 4 4 4 1 3 2 1 5 3 2 0 9 10
输出#1
13 8 20 32
说明/提示
In the first example, you can perform the operation on the subarray [3,3], resulting in the array [2,5,6] and the sum 13.
In the second example, you don't need to perform any operation.
In the third example, you can perform the operation on the subarray [1,4], resulting in the array [5,5,5,5] and the sum 20.
In the fourth example, you can perform the operation on the subarray [2,3], resulting in the array [3,5,5,9,10] and the sum 32.
在第一个例子中,你可以对子数组 [3,3] 执行该操作,得到数组 [2,5,6],其元素和为 13。
在第二个例子中,你无需执行任何操作。
在第三个例子中,你可以对子数组 [1,4] 执行该操作,得到数组 [5,5,5,5],其元素和为 20。
在第四个例子中,你可以对子数组 [2,3] 执行该操作,得到数组 [3,5,5,9,10],其元素和为 32。
输入解题思路,AI测评打分。不知道怎么写?