Sherlock and Cost (Hackerrank)
Array A contains the elements, A1,A2...AN. And array B contains the elements, B1,B2...BN. There is a relationship between Ai and Bi, ∀ 1 ≤ i ≤ N, i.e.,
any element Ai lies between 1 and Bi.
Let the cost S of an array A be defined as:
You have to print the largest possible value of S.
any element Ai lies between 1 and Bi.
Let the cost S of an array A be defined as:
Input Format
The first line contains, T, the number of test cases. Each test case contains an integer, N, in first line. The second line of each test case contains N integers that denote the array B.
Constraints
1 ≤ T ≤ 20
1 ≤ N ≤ 105
1 ≤ Bi ≤ 100
1 ≤ N ≤ 105
1 ≤ Bi ≤ 100
Output Format
For each test case, print the required answer in one line.
Sample Input
1
5
10 1 10 1 10
Sample Output
36
Explanation
The maximum value occurs when A1=A3=A5=10 and A2=A4=1.
Comments
Post a Comment