`{"id":"6618d246-3b45-4bf5-bc9a-0fab010d53cb","name":"Maximize Sum Of Arr[i]*i Of An Array","description":"1. Given an array arr of N integers. \r\n2. Your task is to write a program to find the maximum value of sum of arr[i]*i, where i = 0,1,2,...,n-1.\r\n3. You are allowed to rearrange the elements of the array.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= N &lt;= 10^6\r\n1 &lt;= arr[i] &lt;= 10^5","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint maximise(vector<int>& arr)\n{\n /*Write your code here*/\n}\n\nint main()\n{\n int n;\n cin>>n;\n \n vector<int> arr(n,0);\n for(int i=0;i<n;i++)\n {\n cin>>arr[i];\n }\n \n int ans = maximise(arr);\n cout<<ans;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int maximise(int[]arr) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]arr = new int[n];\r\n for(int i = 0 ; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int ans = maximise(arr);\r\n System.out.println(ans);\r\n }\r\n}"},"python":{"code":"def main():\r\n pass\r\nif_name_=='__main__':\r\n main()"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n2 3 1 5 4","sampleOutput":"40","questionVideo":"https://www.youtube.com/embed/Rax27fL0iIU","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"6bab59c6-598b-434a-bee6-824b630dc3ce","name":"Maximize Sum Of Arr[i]*i Of An Array","slug":"maximize-sum-of-arr-i-i-of-an-array","type":1}],"next":{"id":"c07a75e8-6577-4f1f-a5c7-270a69030cd7","name":"Maximize Sum Of Arr[i]*i Of An Array","type":3,"slug":"maximize-sum-of-arr-i-i-of-an-array"},"prev":{"id":"d9c18f92-c7d1-4b88-86a7-75f1a717b07b","name":"Roof Top Easy MCQ","type":0,"slug":"roof-top-easy-mcq"}}}`

# Maximize Sum Of Arr[i]*i Of An Array

1. Given an array arr of N integers. 2. Your task is to write a program to find the maximum value of sum of arr[i]*i, where i = 0,1,2,...,n-1. 3. You are allowed to rearrange the elements of the array.

`{"id":"6618d246-3b45-4bf5-bc9a-0fab010d53cb","name":"Maximize Sum Of Arr[i]*i Of An Array","description":"1. Given an array arr of N integers. \r\n2. Your task is to write a program to find the maximum value of sum of arr[i]*i, where i = 0,1,2,...,n-1.\r\n3. You are allowed to rearrange the elements of the array.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= N &lt;= 10^6\r\n1 &lt;= arr[i] &lt;= 10^5","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint maximise(vector<int>& arr)\n{\n /*Write your code here*/\n}\n\nint main()\n{\n int n;\n cin>>n;\n \n vector<int> arr(n,0);\n for(int i=0;i<n;i++)\n {\n cin>>arr[i];\n }\n \n int ans = maximise(arr);\n cout<<ans;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int maximise(int[]arr) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n\r\n int[]arr = new int[n];\r\n for(int i = 0 ; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int ans = maximise(arr);\r\n System.out.println(ans);\r\n }\r\n}"},"python":{"code":"def main():\r\n pass\r\nif_name_=='__main__':\r\n main()"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n2 3 1 5 4","sampleOutput":"40","questionVideo":"https://www.youtube.com/embed/Rax27fL0iIU","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"6bab59c6-598b-434a-bee6-824b630dc3ce","name":"Maximize Sum Of Arr[i]*i Of An Array","slug":"maximize-sum-of-arr-i-i-of-an-array","type":1}],"next":{"id":"c07a75e8-6577-4f1f-a5c7-270a69030cd7","name":"Maximize Sum Of Arr[i]*i Of An Array","type":3,"slug":"maximize-sum-of-arr-i-i-of-an-array"},"prev":{"id":"d9c18f92-c7d1-4b88-86a7-75f1a717b07b","name":"Roof Top Easy MCQ","type":0,"slug":"roof-top-easy-mcq"}}}` Editor

# Maximize Sum Of Arr[i]*i Of An Array

easy

1. Given an array arr of N integers. 2. Your task is to write a program to find the maximum value of sum of arr[i]*i, where i = 0,1,2,...,n-1. 3. You are allowed to rearrange the elements of the array.

## Constraints

1 <= N <= 10^6 1 <= arr[i] <= 10^5

## Format

### Input

Input is managed for you

### Output

Output is managed for you

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}5 2 3 1 5 4```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}40`

Question Video

Discussions

Show Discussion

Related Resources 