title: Maximize Sum Arrii
signature: maximize_sum_arrii <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 3L, 4L, 6L, 7L, 8L, 9L, 11L, 19L, 23L, 24L, 30L, 31L, 31L, 32L, 41L, 43L, 43L, 46L, 47L, 50L, 50L, 51L, 53L, 57L, 63L, 63L, 69L, 73L, 74L, 79L, 80L, 81L, 81L, 85L, 86L, 88L, 92L, 93L, 95L, 98L, 99L), 22L, 
          8185L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-98L, -98L, -82L, -80L, -78L, -76L, -74L, -68L, -62L, -58L, -58L, -52L, -42L, -42L, -40L, -34L, -16L, -10L, -10L, -6L, 10L, 12L, 20L, 32L, 52L, 62L, 66L, 68L, 72L, 76L, 76L, 80L, 90L, 90L, 90L, 90L, 92L, 98L), 24L, 
          -5496L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 13L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(8L, 13L, 14L, 42L, 44L, 44L, 44L, 45L, 47L, 52L, 58L, 79L, 98L, 99L), 11L, 
          2566L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-90L, -88L, -68L, -66L, -46L, -42L, -40L, -20L, -16L, 4L, 8L, 8L, 8L, 20L, 28L, 52L, 84L, 98L), 14L, 
          -764L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 13L, 
          23L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(5L, 6L, 7L, 9L, 11L, 13L, 16L, 19L, 22L, 25L, 26L, 27L, 28L, 29L, 32L, 32L, 32L, 33L, 36L, 40L, 43L, 43L, 47L, 49L, 51L, 51L, 52L, 53L, 59L, 61L, 63L, 65L, 66L, 66L, 67L, 72L, 73L, 73L, 75L, 76L, 80L, 86L, 87L, 89L, 89L, 91L, 96L, 98L, 99L), 42L, 
          48954L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-98L, -96L, -90L, -78L, -66L, -52L, -48L, -38L, -34L, -32L, -30L, -26L, -24L, -22L, -20L, -20L, -14L, -14L, -12L, -12L, -8L, -6L, -4L, 2L, 6L, 26L, 28L, 32L, 32L, 34L, 40L, 40L, 48L, 52L, 54L, 64L, 64L, 68L, 70L, 76L, 88L, 92L, 96L), 39L, 
          16394L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 1L, 1L), 3L, 
          2L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(18L, 20L, 21L, 32L, 34L, 44L, 47L, 49L, 49L, 49L, 62L, 71L, 75L, 84L, 84L, 88L, 88L), 8L, 
          1139L
      )))
  
  }
  
  main()
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;
  }