Sequence Cost

 MoEngage has given you an array 

A of N integers and a positive integer C.

You can apply the following operation on the array any number of times. In one operation:

  • Choose a strictly increasing array B of length M such that:
    • B1=1,BM=N, and 1<Bi<N for all (1<i<M);
    • ABi>0 for all (1iM).
  • Subtract 1 from ABi for all (1iM).
    The cost of this operation is i=1(M1)(Bi+1Bi)2.

Note that, M can be different for different operations.

Let K be the total cost after performing X number of operations on the array. Your goal is to maximize the value of (CXK).

Input Format

  • First line contains a single integer T, denoting the number of test cases.
  • For each of the T test cases, the first line contains two integers N and C.
  • The next line contains N space-separated integers denoting A1,A2,,AN.

Output Format

For each test case, output a single integer - the maximum value of (CXK).

Constraints

  • 1T104
  • 2N2105
  • 1C,Ai109
  • Sum of N over all test cases does not exceed 2105.

Sample Input 1 

3
3 3
3 1 5
7 5
5 5 5 4 1 2 1
2 10
3 3

Sample Output 1 

1
0
27

Explanation

  • Test case 1: Given N=3A=[3,1,5]C=3.
    It is optimal to apply only 1 operation with B=[1,2,3]. The cost for the operation would be (21)2+(32)2=2. The value of X=1 and the total cost K=2. Thus, (CXK)=(312)=1.
    After the operation, the array becomes A=[2,0,4].

  • Test case 2: Given N=7A=[5,5,5,4,1,2,1]C=5.
    It can be proven that it is never optimal to apply any operation. Hence, the answer will be (500)=0.

  • Test case 3: Given N=2A=[3,3]C=10.
    It is optimal to apply 3 operations on the array. In each operation, it is optimal to take B=[1,2]. The cost for each operation would be (21)2=1. Thus, X=3 and total cost K=1+1+1=3. Thus, (CXK)=(1033)=27.
    After all the operations, the array becomes A=[0,0].

Previous
Next Post »