Max sum in the configuration
Submissions: 12544   Accuracy:

49.48%

  Difficulty: Easy   Marks: 2

Given an array you have to find  the max sum of i*A[i] where i is the index of the array obtained by rotating the element of the array one by one . Your task is to complete the function max_sum which takes one argument which is the array A [ ] and returns an integer value denoting  the required max sum .

Input:
The first line of input is the number of test cases T . Then T test cases follow . The first line of each test case is an integer N  denoting the size of the array . Then in the next line are N space separated values of the array A [ ] . 

Output:
For each test case output will be the required max sum.

Constraints:
1<=T<=100
1<=N<=100
1<=A[]<1000

Example:
Input
1
4
8 3 1 2
Output
29


Explanation
Above the configuration possible by rotating elements are
3 1 2 8 here sum is 3*0+1*1+2*2+8*3 = 29
1 2 8 3 here sum is 1*0+2*1+8*2+3*3 = 27
2 8 3 1 here sum is 2*0+8*1+3*2+1*3 = 17
8 3 1 2 here sum is 8*0+3*1+1*2+2*3 =  11
Here the max sum is 29 


Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Amit Khandelwal, Harshit Sidhwa
Author: Shubham Joshi 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.