title: Maximum Average Sum Partition Array
signature: function maximum_average_sum_partition_array(a, k)
source_py: def maximum_average_sum_partition_array(A, K):
      n = len(A)
      pre_sum = ([0] * (n + 1))
      pre_sum[0] = 0
      for i in range(n):
          pre_sum[(i + 1)] = (pre_sum[i] + A[i])
      dp = ([0] * n)
      sum = 0
      for i in range(n):
          dp[i] = ((pre_sum[n] - pre_sum[i]) / (n - i))
      for k in range((K - 1)):
          for i in range(n):
              for j in range((i + 1), n):
                  dp[i] = max(dp[i], (((pre_sum[j] - pre_sum[i]) / (j - i)) + dp[j]))
      return int(dp[0])
source_cpp: double maximum_average_sum_partition_array(vector < int > & A, int K) {
    int n = A . size ( );
    double pre_sum [ n + 1 ];
    pre_sum [ 0 ] = 0;
    for ( int i = 0;
    i < n;
    i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ];
    double dp [ n ] = {
      0 };
      double sum = 0;
      for ( int i = 0;
      i < n;
      i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i );
      for ( int k = 0;
      k < K - 1;
      k ++ ) for ( int i = 0;
      i < n;
      i ++ ) for ( int j = i + 1;
      j < n;
      j ++ ) dp [ i ] = max ( dp [ i ], ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] );
      return dp [ 0 ];
    }
question_info.entry_fn_name: maximum_average_sum_partition_array
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(a, k, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(a, k) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({4, 11, 14, 27, 32, 37, 39, 49, 52, 53, 57, 62, 67, 67, 68, 69, 76, 77, 78, 81, 85, 85, 87, 91, 91, 91, 99, 99, 99}, 24, 1742)
      print(string.format("TEST-0...%s",result))
  
      result = driver({80, 12, 32, 44, 24, 82, -40, 42, 26, 36, 58, 52, -34, 44, 12, -18, -72, 52, 2, -8, 22, -18, 98, -60, 62, 92, -46, 20, 20, -46, 52, 94, 0, -28, -22, 80, 26, -92, -50, 48, -80}, 26, 856)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 15, 11)
      print(string.format("TEST-2...%s",result))
  
      result = driver({32, 16, 67, 53, 99, 56, 80, 92, 84, 21, 36, 46, 94, 31, 63, 67, 59, 88, 41, 17, 74, 47, 95, 12, 27, 99, 32, 4, 82, 31, 65, 40, 93, 72, 23, 33, 93, 9, 62, 47}, 36, 2092)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-92, -86, -80, -78, -72, -70, -70, -68, -66, -62, -60, -54, -54, -52, -52, -40, -36, -32, -28, -26, -22, -22, -20, -16, -16, -8, 0, 6, 8, 10, 14, 18, 20, 42, 46, 52, 60, 66, 68, 70, 74, 86, 88, 88, 92, 94, 98}, 36, 1052)
      print(string.format("TEST-4...%s",result))
  
      result = driver({1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0}, 16, 10)
      print(string.format("TEST-5...%s",result))
  
      result = driver({1, 1, 3, 3, 6, 7, 10, 11, 12, 13, 16, 16, 22, 23, 24, 27, 28, 30, 30, 30, 31, 33, 35, 35, 39, 40, 41, 52, 52, 58, 59, 60, 61, 61, 66, 66, 71, 73, 74, 75, 75, 76, 80, 83, 85, 95, 96, 97, 97}, 34, 1996)
      print(string.format("TEST-6...%s",result))
  
      result = driver({28, -52, 48, 96, 54, 94, 60, 18}, 7, 358)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 1}, 31, 22)
      print(string.format("TEST-8...%s",result))
  
      result = driver({26, 80, 12, 87, 90, 98, 46, 91, 38, 46, 20, 64, 53, 4, 60, 87, 44, 88, 22, 30}, 19, 1060)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 1742, "inputs": {"a": [4, 11, 14, 27, 32, 37, 39, 49, 52, 53, 57, 62, 67, 67, 68, 69, 76, 77, 78, 81, 85, 85, 87, 91, 91, 91, 99, 99, 99], "k": 24}}, {"idx": 1, "outputs": 856, "inputs": {"a": [80, 12, 32, 44, 24, 82, -40, 42, 26, 36, 58, 52, -34, 44, 12, -18, -72, 52, 2, -8, 22, -18, 98, -60, 62, 92, -46, 20, 20, -46, 52, 94, 0, -28, -22, 80, 26, -92, -50, 48, -80], "k": 26}}, {"idx": 2, "outputs": 11, "inputs": {"a": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "k": 15}}, {"idx": 3, "outputs": 2092, "inputs": {"a": [32, 16, 67, 53, 99, 56, 80, 92, 84, 21, 36, 46, 94, 31, 63, 67, 59, 88, 41, 17, 74, 47, 95, 12, 27, 99, 32, 4, 82, 31, 65, 40, 93, 72, 23, 33, 93, 9, 62, 47], "k": 36}}, {"idx": 4, "outputs": 1052, "inputs": {"a": [-92, -86, -80, -78, -72, -70, -70, -68, -66, -62, -60, -54, -54, -52, -52, -40, -36, -32, -28, -26, -22, -22, -20, -16, -16, -8, 0, 6, 8, 10, 14, 18, 20, 42, 46, 52, 60, 66, 68, 70, 74, 86, 88, 88, 92, 94, 98], "k": 36}}, {"idx": 5, "outputs": 10, "inputs": {"a": [1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0], "k": 16}}, {"idx": 6, "outputs": 1996, "inputs": {"a": [1, 1, 3, 3, 6, 7, 10, 11, 12, 13, 16, 16, 22, 23, 24, 27, 28, 30, 30, 30, 31, 33, 35, 35, 39, 40, 41, 52, 52, 58, 59, 60, 61, 61, 66, 66, 71, 73, 74, 75, 75, 76, 80, 83, 85, 95, 96, 97, 97], "k": 34}}, {"idx": 7, "outputs": 358, "inputs": {"a": [28, -52, 48, 96, 54, 94, 60, 18], "k": 7}}, {"idx": 8, "outputs": 22, "inputs": {"a": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 1], "k": 31}}, {"idx": 9, "outputs": 1060, "inputs": {"a": [26, 80, 12, 87, 90, 98, 46, 91, 38, 46, 20, 64, 53, 4, 60, 87, 44, 88, 22, 30], "k": 19}}]