Given an integer array 𝐴 A ( 1 1-indexed) with even length 𝑛 n. You can do the…
- User
Given an integer array 𝐴 A ( 1 1-indexed) with even length 𝑛 n. You can do the following operation as many times as you want:
Choose a pair of positions 2 𝑘 − 1 2k−1 and 2 𝑘 2k and multiply both 𝐴 2 𝑘 − 1 A 2k−1 and 𝐴 2 𝑘 A 2k by − 1 −1. After finishing your operations, you must compute the maximum subarray sum of the resulting array. Maximize this value.
Standard input The first line contains an integer 𝑇 T, the number of test cases.
The following lines describe 𝑡 t test cases. The first line of each test case contains an even integer 𝑁 𝑖 N i , the length of the array. The second line contains 𝑁 𝑖 N i integers 𝐴 𝑗 A j , the 𝑗 j-th integer is the 𝑗 j-th element of the array.
Standard output Print 𝑡 t lines, the 𝑖 i-th line must contain the answer to the 𝑖 i-th test case.
Constraints and notes 1 ≤ 𝑇 ≤ 1 0 5 1≤T≤10 5 . 1 ≤ ∑ 𝑖
1 𝑇 𝑁 𝑖 ≤ 4 ∗ 1 0 5 1≤ i=1 ∑ T N i ≤4∗10 5 . 2 ≤ 𝑁 𝑖 ≤ 2 ∗ 1 0 5 2≤N i ≤2∗10 5 for every 𝑖
1 , … , 𝑇 i=1,…,T. 𝑁 𝑖 N i is even for every 𝑖
1 , … , 𝑇 i=1,…,T. ∣ 𝐴 𝑗 ∣ ≤ 1 0 4 ∣A j ∣≤10 4 for every valid 𝑗 j. Input Output Explanation 3 4 5 -10 7 -2 2 7 -8 2 5 4 17 8 9 For the first test case, it's possible to apply the operation on position 2 2, which gives the array ( − 5 , 10 , 7 , − 2 ) (−5,10,7,−2) and its maximum subarray sum is 10 + 7
17 10+7=17.
For the second test case, it's possible to apply the operation on position 2 2, which gives the array ( − 7 , 8 ) (−7,8) and its maximum subarray sum is 8 8.
For the third test case, there is no need to apply the operation since all the values are positive, so the maximum subarray sum is 5 + 4
9 5+4=9 2 6 -8 -6 9 5 -6 -10 2 -1 -8 44 9 For the first test case, it's possible to apply the operation on positions 2 2 and 6 6, which gives the array ( 8 , 6 , 9 , 5 , 6 , 10 ) (8,6,9,5,6,10) and its maximum subarray sum is 8 + 6 + 9 + 5 + 6 + 10
44 8+6+9+5+6+10=44.
For the second test case, it's possible to apply the operation on position 2 2, which gives the array ( 1 , 8 ) (1,8) and its maximum subarray sum is 1 + 8
9 1+8=9 .
2 6 9 -5 -3 8 0 -6 2 -8 0 16 8 For the first test case, it's possible to apply the operation on positions 2 2 and 6 6, which gives the array ( − 9 , 5 , − 3 , 8 , 0 , 6 ) (−9,5,−3,8,0,6) and its maximum subarray sum is 5 + ( − 3 ) + 8 + 0 + 6
16 5+(−3)+8+0+6=16.
For the second test case, it's possible to apply the operation on position 2 2, which gives the array ( 8 , 0 ) (8,0) and its maximum subarray sum is 8 + 0
8 8+0=8 .
3 2 -9 0 2 -2 1 6 -6 3 7 1 -4 -6 9 2 21 For the first test case, it's possible to apply the operation on position 2 2, which gives the array ( 9 , 0 ) (9,0) and its maximum subarray sum is 9 + 0
9 9+0=9 .
For the second test case, it's possible to apply the operation on position 2 2, which gives the array ( 2 , − 1 ) (2,−1) and its maximum subarray sum is 2 2 .
- Assistant