title: Difference Maximum Sum Minimum Sum N M Elementsin Review
signature: difference_maximum_sum_minimum_sum_n_m_elementsin_review <- function(arr, n, m) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, m, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n, m), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 3L, 6L, 16L, 21L, 22L, 23L, 27L, 27L, 28L, 29L, 29L, 31L, 31L, 37L, 37L, 38L, 40L, 41L, 43L, 51L, 52L, 53L, 55L, 55L, 56L, 57L, 63L, 67L, 67L, 67L, 72L, 75L, 79L, 82L, 84L, 91L, 92L, 93L, 96L, 96L, 97L), 21L, 25L, 
          167L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-92L, -62L, -50L, -40L, -32L, -30L, -18L, -16L, -14L, -10L, 24L, 48L, 54L, 58L, 94L), 8L, 12L, 
          206L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L), 1L, 1L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(1L, 2L, 2L, 4L, 5L, 6L, 7L, 9L, 10L, 11L, 11L, 12L, 13L, 13L, 16L, 17L, 21L, 24L, 29L, 29L, 34L, 44L, 44L, 48L, 49L, 51L, 54L, 56L, 59L, 62L, 63L, 65L, 65L, 65L, 71L, 71L, 76L, 77L, 77L, 80L, 83L, 83L, 84L, 89L, 91L, 97L, 99L), 31L, 34L, 
          92L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-90L, -58L, 6L, 16L, 20L, 34L, 36L, 38L, 48L, 66L, 82L, 84L, 86L, 90L, 90L), 14L, 8L, 
          528L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 1L, 1L), 3L, 2L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(7L, 12L, 15L, 15L, 21L, 37L, 40L, 45L, 50L, 52L, 53L, 68L, 68L, 72L, 75L, 78L, 86L, 86L, 88L), 16L, 18L, 
          2L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-88L, -20L, 22L, 44L, 72L, 94L), 4L, 3L, 
          132L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 25L, 17L, 
          8L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(4L, 11L, 21L, 25L, 26L, 30L, 32L, 38L, 60L, 63L, 65L, 75L, 77L, 87L, 87L, 96L), 12L, 15L, 
          19L
      )))
  
  }
  
  main()
source_py: def difference_maximum_sum_minimum_sum_n_m_elementsin_review(arr, n, m):
      max = 0
      min = 0
      arr.sort()
      j = (n - 1)
      for i in range(m):
          min += arr[i]
          max += arr[j]
          j = (j - 1)
      return (max - min)
source_cpp: int difference_maximum_sum_minimum_sum_n_m_elementsin_review(vector<int> arr, int n, int m) {
    int max = 0, min = 0;
    sort(arr.begin(), arr.end());
    for ( int i = 0, j = n - 1;
    i < m;
    i ++, j -- ) {
      min += arr [ i ];
      max += arr [ j ];
    }
    return ( max - min );
  }