title: Difference Maximum Sum Minimum Sum N M Elementsin Review
signature: fun differenceMaximumSumMinimumSumNMElementsinReview(arr: ArrayList<Int>, n: Int, m: Int): Int {
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 );
  }
question_info.test_list: [{"idx": 0, "outputs": 167, "inputs": {"arr": [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], "n": 21, "m": 25}}, {"idx": 1, "outputs": 206, "inputs": {"arr": [-92, -62, -50, -40, -32, -30, -18, -16, -14, -10, 24, 48, 54, 58, 94], "n": 8, "m": 12}}, {"idx": 2, "outputs": 0, "inputs": {"arr": [0, 0], "n": 1, "m": 1}}, {"idx": 3, "outputs": 92, "inputs": {"arr": [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], "n": 31, "m": 34}}, {"idx": 4, "outputs": 528, "inputs": {"arr": [-90, -58, 6, 16, 20, 34, 36, 38, 48, 66, 82, 84, 86, 90, 90], "n": 14, "m": 8}}, {"idx": 5, "outputs": 0, "inputs": {"arr": [0, 0, 0, 1, 1], "n": 3, "m": 2}}, {"idx": 6, "outputs": 2, "inputs": {"arr": [7, 12, 15, 15, 21, 37, 40, 45, 50, 52, 53, 68, 68, 72, 75, 78, 86, 86, 88], "n": 16, "m": 18}}, {"idx": 7, "outputs": 132, "inputs": {"arr": [-88, -20, 22, 44, 72, 94], "n": 4, "m": 3}}, {"idx": 8, "outputs": 8, "inputs": {"arr": [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], "n": 25, "m": 17}}, {"idx": 9, "outputs": 19, "inputs": {"arr": [4, 11, 21, 25, 26, 30, 32, 38, 60, 63, 65, 75, 77, 87, 87, 96], "n": 12, "m": 15}}]
question_info.extension: kts
question_info.test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Int, expected:Int):Boolean{
    return actual.equals(expected)
  }
  fun driver(arr: ArrayList<Int>, n: Int, m: Int, expected:Int):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, m), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(arrayListOf(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)
      println("TEST-0...${result}")
      
      result = driver(arrayListOf(-92, -62, -50, -40, -32, -30, -18, -16, -14, -10, 24, 48, 54, 58, 94), 8, 12, 206)
      println("TEST-1...${result}")
      
      result = driver(arrayListOf(0, 0), 1, 1, 0)
      println("TEST-2...${result}")
      
      result = driver(arrayListOf(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)
      println("TEST-3...${result}")
      
      result = driver(arrayListOf(-90, -58, 6, 16, 20, 34, 36, 38, 48, 66, 82, 84, 86, 90, 90), 14, 8, 528)
      println("TEST-4...${result}")
      
      result = driver(arrayListOf(0, 0, 0, 1, 1), 3, 2, 0)
      println("TEST-5...${result}")
      
      result = driver(arrayListOf(7, 12, 15, 15, 21, 37, 40, 45, 50, 52, 53, 68, 68, 72, 75, 78, 86, 86, 88), 16, 18, 2)
      println("TEST-6...${result}")
      
      result = driver(arrayListOf(-88, -20, 22, 44, 72, 94), 4, 3, 132)
      println("TEST-7...${result}")
      
      result = driver(arrayListOf(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)
      println("TEST-8...${result}")
      
      result = driver(arrayListOf(4, 11, 21, 25, 26, 30, 32, 38, 60, 63, 65, 75, 77, 87, 87, 96), 12, 15, 19)
      println("TEST-9...${result}")
      
          
  }
  
  main()
question_info.entry_fn_name: differenceMaximumSumMinimumSumNMElementsinReview
question_info.entry_cls_name: Solution
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: kotlinc -script __FILENAME__ -no-reflect -nowarn