Rearrange an array to maximize i * arr [ i ] | C # program for the Optimal Solution ; Function to calculate the maximum points earned by making an optimal selection on the given array ; Sorting the array ; Variable to store the total points earned ; Driver code
using System ; public class GFG { static int findOptimalSolution ( int [ ] a , int N ) { Array . Sort ( a ) ; int points = 0 ; for ( int i = 0 ; i < N ; i ++ ) { points += a [ i ] * i ; } return points ; } static public void Main ( ) { int [ ] a = { 1 , 4 , 2 , 3 , 9 } ; int N = a . Length ; Console . WriteLine ( findOptimalSolution ( a , N ) ) ; } }