title: Maximize Sum Arrii
signature: def maximizeSumArrii(arr: List[Int], n: Int) = {
test_code: import scala.collection.mutable.HashMap
  import scala.collection.immutable.HashSet
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  
  // TESTING CODE 
  // ============================================
  def validateSolution(actual: Int , expected: Int): Boolean = {
      actual.toString == expected.toString
  }
  
  def driver(arr: List[Int], n: Int, expected: Int): String = {
      try {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, n),expected)) {
              "PASSED"
          } else{
              "FAILED"
          }
      }catch{
          case e: Exception => {e.getClass.getName}
      }
  
  }
  object QuestionEvaluator extends App {
  
      println(s"TEST-0...${driver(
        List(2, 3, 4, 6, 7, 8, 9, 11, 19, 23, 24, 30, 31, 31, 32, 41, 43, 43, 46, 47, 50, 50, 51, 53, 57, 63, 63, 69, 73, 74, 79, 80, 81, 81, 85, 86, 88, 92, 93, 95, 98, 99), 22, 
        8185    
      )}")   
  
  
      println(s"TEST-1...${driver(
        List(-98, -98, -82, -80, -78, -76, -74, -68, -62, -58, -58, -52, -42, -42, -40, -34, -16, -10, -10, -6, 10, 12, 20, 32, 52, 62, 66, 68, 72, 76, 76, 80, 90, 90, 90, 90, 92, 98), 24, 
        -5496    
      )}")   
  
  
      println(s"TEST-2...${driver(
        List(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1), 13, 
        0    
      )}")   
  
  
      println(s"TEST-3...${driver(
        List(8, 13, 14, 42, 44, 44, 44, 45, 47, 52, 58, 79, 98, 99), 11, 
        2566    
      )}")   
  
  
      println(s"TEST-4...${driver(
        List(-90, -88, -68, -66, -46, -42, -40, -20, -16, 4, 8, 8, 8, 20, 28, 52, 84, 98), 14, 
        -764    
      )}")   
  
  
      println(s"TEST-5...${driver(
        List(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), 13, 
        23    
      )}")   
  
  
      println(s"TEST-6...${driver(
        List(5, 6, 7, 9, 11, 13, 16, 19, 22, 25, 26, 27, 28, 29, 32, 32, 32, 33, 36, 40, 43, 43, 47, 49, 51, 51, 52, 53, 59, 61, 63, 65, 66, 66, 67, 72, 73, 73, 75, 76, 80, 86, 87, 89, 89, 91, 96, 98, 99), 42, 
        48954    
      )}")   
  
  
      println(s"TEST-7...${driver(
        List(-98, -96, -90, -78, -66, -52, -48, -38, -34, -32, -30, -26, -24, -22, -20, -20, -14, -14, -12, -12, -8, -6, -4, 2, 6, 26, 28, 32, 32, 34, 40, 40, 48, 52, 54, 64, 64, 68, 70, 76, 88, 92, 96), 39, 
        16394    
      )}")   
  
  
      println(s"TEST-8...${driver(
        List(0, 0, 1, 1), 3, 
        2    
      )}")   
  
  
      println(s"TEST-9...${driver(
        List(18, 20, 21, 32, 34, 44, 47, 49, 49, 49, 62, 71, 75, 84, 84, 88, 88), 8, 
        1139    
      )}")   
  
  }
  
source_py: def maximize_sum_arrii(arr, n):
      arr.sort()
      sum = 0
      for i in range(n):
          sum += (arr[i] * i)
      return sum
source_cpp: int maximize_sum_arrii(vector<int> arr, int n) {
    sort(arr.begin(), arr.end());
    int sum = 0;
    for ( int i = 0;
    i < n;
    i ++ ) sum += ( arr [ i ] * i );
    return sum;
  }