[Solution] Mainak and Array Codeforces Solution
Mainak has an array of positive integers. He will do the following operation to this array exactly once:
- Pick a subsegment of this array and cyclically rotate it by any amount.
- Pick two integers and , such that , and any positive integer .
- Repeat this times: set (all changes happen at the same time).
Mainak wants to maximize the value of after exactly one such operation. Determine the maximum value of that he can obtain.
Each test contains multiple test cases. The first line contains a single integer () — the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer ().
The second line of each test case contains integers ().
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output a single integer — the maximum value of that Mainak can obtain by doing the operation exactly once.
- In the first test case, we can rotate the subarray from index to index by an amount of (i.e. choose , and ) to get the optimal array:So the answer is .
- In the second testcase, it is optimal to rotate the subarray starting and ending at index and rotating it by an amount of .
- In the fourth testcase, it is optimal to rotate the subarray starting from index to index and rotating it by an amount of . So the answer is .
No comments:
Post a Comment