title: Difference Maximum Sum Minimum Sum N M Elementsin Review
signature: class Solution {
  
      public int DifferenceMaximumSumMinimumSumNMElementsinReview(List<int> arr, int n, int m) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> arr, int n, int m, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(arr, n, m); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  new List<int>{2, 3, 6, 16, 21, 22, 23, 27, 27, 28, 29, 29, 31, 31, 37, 37, 38, 40, 41, 43, 51, 52, 53, 55, 55, 56, 57, 63, 67, 67, 67, 72, 75, 79, 82, 84, 91, 92, 93, 96, 96, 97}, 21, 25, 
                  167
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-92, -62, -50, -40, -32, -30, -18, -16, -14, -10, 24, 48, 54, 58, 94}, 8, 12, 
                  206
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0}, 1, 1, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{1, 2, 2, 4, 5, 6, 7, 9, 10, 11, 11, 12, 13, 13, 16, 17, 21, 24, 29, 29, 34, 44, 44, 48, 49, 51, 54, 56, 59, 62, 63, 65, 65, 65, 71, 71, 76, 77, 77, 80, 83, 83, 84, 89, 91, 97, 99}, 31, 34, 
                  92
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-90, -58, 6, 16, 20, 34, 36, 38, 48, 66, 82, 84, 86, 90, 90}, 14, 8, 
                  528
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 1, 1}, 3, 2, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{7, 12, 15, 15, 21, 37, 40, 45, 50, 52, 53, 68, 68, 72, 75, 78, 86, 86, 88}, 16, 18, 
                  2
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-88, -20, 22, 44, 72, 94}, 4, 3, 
                  132
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 25, 17, 
                  8
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{4, 11, 21, 25, 26, 30, 32, 38, 60, 63, 65, 75, 77, 87, 87, 96}, 12, 15, 
                  19
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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 );
  }