CF2169C.Range Operation

普及-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given an integer array aa of length nn.

You can perform the following operation: choose a range [l,r][l, r] (1≤l≤r≤n1 \le l \le r \le n) and replace the value of elements al,al+1,…,ara_l, a_{l+1}, \dots, a_r with (l+r)(l + r).

Your task is to calculate the maximum possible total array sum if you can perform the aforementioned operation at most once.

给你一个长度为 nn 的整数数组 aa。

你可以执行以下操作:选择一个区间 [l,r][l, r](其中 1≤l≤r≤n1 \le l \le r \le n),并将元素 al,al+1,…,ara_l, a_{l+1}, \dots, a_r 的值全部替换为 (l+r)(l + r)。

你的任务是:在最多执行一次上述操作的前提下,计算数组总和的最大可能值。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

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

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai≤2n0 \le a_i \le 2n).

Additional constraint on the input: the sum of nn over all test cases doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

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

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤2n0 \le a_i \le 2n)。

输入的额外约束:所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

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][3, 3], resulting in the array [2,5,6][2, 5, 6] and the sum 1313.

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][1, 4], resulting in the array [5,5,5,5][5, 5, 5, 5] and the sum 2020.

In the fourth example, you can perform the operation on the subarray [2,3][2, 3], resulting in the array [3,5,5,9,10][3, 5, 5, 9, 10] and the sum 3232.

在第一个例子中,你可以对子数组 [3,3][3, 3] 执行该操作,得到数组 [2,5,6][2, 5, 6],其元素和为 1313。

在第二个例子中,你无需执行任何操作。

在第三个例子中,你可以对子数组 [1,4][1, 4] 执行该操作,得到数组 [5,5,5,5][5, 5, 5, 5],其元素和为 2020。

在第四个例子中,你可以对子数组 [2,3][2, 3] 执行该操作,得到数组 [3,5,5,9,10][3, 5, 5, 9, 10],其元素和为 3232。

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

首页