title: Maximum Average Sum Partition Array
signature: def 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.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(a, k, expected):
      try:
          if validate_solution(PLACEHOLDER_FN_NAME(
              a, k),
              expected
          ):
              return "PASSED"
          return "FAILED"
      except Exception as exception_obj:
          return type(exception_obj).__name__
      
  if __name__ == "__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(f"TEST-0...{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(f"TEST-1...{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(f"TEST-2...{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(f"TEST-3...{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(f"TEST-4...{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(f"TEST-5...{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(f"TEST-6...{result}")
  
      result = driver([28, -52, 48, 96, 54, 94, 60, 18], 7, 358)
      print(f"TEST-7...{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(f"TEST-8...{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(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: maximum_average_sum_partition_array
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}}]
question_info.entry_cls_name: Solution