title: Maximum Average Sum Partition Array
signature: function maximumAverageSumPartitionArray(a, k) {
test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value) {
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual, expected){
      return convertToString(actual)===convertToString(expected);
  }
  
  function driver(a, k, expected){
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(a, k),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    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);
    console.log(`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);
    console.log(`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);
    console.log(`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);
    console.log(`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);
    console.log(`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);
    console.log(`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);
    console.log(`TEST-6...${result}`);
  
    result = driver([28, -52, 48, 96, 54, 94, 60, 18], 7, 358);
    console.log(`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);
    console.log(`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);
    console.log(`TEST-9...${result}`);
  
    process.exit(0);
  };
  
  if (require.main === module) {
    main();
  }
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 ];
    }