title: Chocolate Distribution Problem
signature: def chocolate_distribution_problem(arr, n, m):
source_py: def chocolate_distribution_problem(arr, n, m):
      if ((m == 0) or (n == 0)):
          return 0
      arr.sort()
      if (n < m):
          return (- 1)
      min_diff = sys.maxsize
      first = 0
      last = 0
      i = 0
      while (((i + m) - 1) < n):
          diff = (arr[((i + m) - 1)] - arr[i])
          if (diff < min_diff):
              min_diff = diff
              first = i
              last = ((i + m) - 1)
          i += 1
      return (arr[last] - arr[first])
source_cpp: int chocolate_distribution_problem(vector<int> arr, int n, int m) {
    if ( m == 0 || n == 0 ) return 0;
    sort(arr.begin(), arr.end());
    if ( n < m ) return - 1;
    int min_diff = INT_MAX;
    int first = 0, last = 0;
    for ( int i = 0;
    i + m - 1 < n;
    i ++ ) {
      int diff = arr [ i + m - 1 ] - arr [ i ];
      if ( diff < min_diff ) {
        min_diff = diff;
        first = i;
        last = i + m - 1;
      }
    }
    return ( arr [ last ] - arr [ first ] );
  }
question_info.test_code: import array
  import bisect
  import collections
  import datetime
  import functools
  import heapq
  import itertools
  import math
  import queue
  import re
  import string
  import sys
  from typing import Any, Dict, List, Optional, Set
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  def validate_solution(actual, expected):
      return actual == expected
  
  def driver(arr, n, m, expected):
      try:
          if validate_solution(PLACEHOLDER_FN_NAME(
              arr, n, m),
              expected
          ):
              return "PASSED"
          return "FAILED"
      except Exception as exception_obj:
          return type(exception_obj).__name__
      
  if __name__ == "__main__":
      result = driver([2, 5, 11, 23, 33, 35, 39, 51, 52, 56, 74, 76, 76, 79, 85, 88, 93, 98], 16, 13, 65)
      print(f"TEST-0...{result}")
  
      result = driver([-94, -94, -88, -84, -74, -70, -56, -50, -48, -42, -34, -24, -18, -14, 0, 4, 4, 16, 16, 30, 36, 42, 52, 56, 72, 74, 76, 84, 88], 15, 28, -1)
      print(f"TEST-1...{result}")
  
      result = driver([0, 0, 1, 1, 1, 1], 5, 5, 1)
      print(f"TEST-2...{result}")
  
      result = driver([3, 4, 5, 5, 12, 16, 16, 16, 18, 29, 37, 38, 40, 43, 44, 49, 57, 60, 62, 63, 67, 69, 73, 74, 75, 76, 78, 84, 85, 86, 88, 89, 92], 25, 18, 57)
      print(f"TEST-3...{result}")
  
      result = driver([-98, -80, -50, -44, -42, -36, -36, -28, -10, -8, -4, -2, 2, 10, 18, 18, 26, 32, 36, 56, 80, 86, 88, 90], 16, 12, 60)
      print(f"TEST-4...{result}")
  
      result = driver([0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 13, 14, -1)
      print(f"TEST-5...{result}")
  
      result = driver([13, 15, 62, 65, 87], 3, 4, -1)
      print(f"TEST-6...{result}")
  
      result = driver([-92, -88, -88, -80, -76, -62, -60, -60, -50, -48, -36, -36, -32, -26, -14, -8, 4, 18, 18, 22, 28, 30, 30, 32, 48, 48, 58, 60, 64, 72, 78, 82, 94], 31, 17, 90)
      print(f"TEST-7...{result}")
  
      result = driver([0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], 9, 6, 1)
      print(f"TEST-8...{result}")
  
      result = driver([17, 23, 25, 38, 40, 53, 58, 73, 77], 8, 6, 35)
      print(f"TEST-9...{result}")
  
      sys.exit(0)
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.entry_fn_name: chocolate_distribution_problem
question_info.test_list: [{"idx": 0, "outputs": 65, "inputs": {"arr": [2, 5, 11, 23, 33, 35, 39, 51, 52, 56, 74, 76, 76, 79, 85, 88, 93, 98], "n": 16, "m": 13}}, {"idx": 1, "outputs": -1, "inputs": {"arr": [-94, -94, -88, -84, -74, -70, -56, -50, -48, -42, -34, -24, -18, -14, 0, 4, 4, 16, 16, 30, 36, 42, 52, 56, 72, 74, 76, 84, 88], "n": 15, "m": 28}}, {"idx": 2, "outputs": 1, "inputs": {"arr": [0, 0, 1, 1, 1, 1], "n": 5, "m": 5}}, {"idx": 3, "outputs": 57, "inputs": {"arr": [3, 4, 5, 5, 12, 16, 16, 16, 18, 29, 37, 38, 40, 43, 44, 49, 57, 60, 62, 63, 67, 69, 73, 74, 75, 76, 78, 84, 85, 86, 88, 89, 92], "n": 25, "m": 18}}, {"idx": 4, "outputs": 60, "inputs": {"arr": [-98, -80, -50, -44, -42, -36, -36, -28, -10, -8, -4, -2, 2, 10, 18, 18, 26, 32, 36, 56, 80, 86, 88, 90], "n": 16, "m": 12}}, {"idx": 5, "outputs": -1, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 13, "m": 14}}, {"idx": 6, "outputs": -1, "inputs": {"arr": [13, 15, 62, 65, 87], "n": 3, "m": 4}}, {"idx": 7, "outputs": 90, "inputs": {"arr": [-92, -88, -88, -80, -76, -62, -60, -60, -50, -48, -36, -36, -32, -26, -14, -8, 4, 18, 18, 22, 28, 30, 30, 32, 48, 48, 58, 60, 64, 72, 78, 82, 94], "n": 31, "m": 17}}, {"idx": 8, "outputs": 1, "inputs": {"arr": [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], "n": 9, "m": 6}}, {"idx": 9, "outputs": 35, "inputs": {"arr": [17, 23, 25, 38, 40, 53, 58, 73, 77], "n": 8, "m": 6}}]
question_info.entry_cls_name: Solution