title: Maximum Average Sum Partition Array
signature: maximum_average_sum_partition_array <- function(a, k) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(a, k, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(a, k), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(4L, 11L, 14L, 27L, 32L, 37L, 39L, 49L, 52L, 53L, 57L, 62L, 67L, 67L, 68L, 69L, 76L, 77L, 78L, 81L, 85L, 85L, 87L, 91L, 91L, 91L, 99L, 99L, 99L), 24L, 
          1742L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(80L, 12L, 32L, 44L, 24L, 82L, -40L, 42L, 26L, 36L, 58L, 52L, -34L, 44L, 12L, -18L, -72L, 52L, 2L, -8L, 22L, -18L, 98L, -60L, 62L, 92L, -46L, 20L, 20L, -46L, 52L, 94L, 0L, -28L, -22L, 80L, 26L, -92L, -50L, 48L, -80L), 26L, 
          856L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 15L, 
          11L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(32L, 16L, 67L, 53L, 99L, 56L, 80L, 92L, 84L, 21L, 36L, 46L, 94L, 31L, 63L, 67L, 59L, 88L, 41L, 17L, 74L, 47L, 95L, 12L, 27L, 99L, 32L, 4L, 82L, 31L, 65L, 40L, 93L, 72L, 23L, 33L, 93L, 9L, 62L, 47L), 36L, 
          2092L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-92L, -86L, -80L, -78L, -72L, -70L, -70L, -68L, -66L, -62L, -60L, -54L, -54L, -52L, -52L, -40L, -36L, -32L, -28L, -26L, -22L, -22L, -20L, -16L, -16L, -8L, 0L, 6L, 8L, 10L, 14L, 18L, 20L, 42L, 46L, 52L, 60L, 66L, 68L, 70L, 74L, 86L, 88L, 88L, 92L, 94L, 98L), 36L, 
          1052L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L), 16L, 
          10L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(1L, 1L, 3L, 3L, 6L, 7L, 10L, 11L, 12L, 13L, 16L, 16L, 22L, 23L, 24L, 27L, 28L, 30L, 30L, 30L, 31L, 33L, 35L, 35L, 39L, 40L, 41L, 52L, 52L, 58L, 59L, 60L, 61L, 61L, 66L, 66L, 71L, 73L, 74L, 75L, 75L, 76L, 80L, 83L, 85L, 95L, 96L, 97L, 97L), 34L, 
          1996L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(28L, -52L, 48L, 96L, 54L, 94L, 60L, 18L), 7L, 
          358L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 31L, 
          22L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(26L, 80L, 12L, 87L, 90L, 98L, 46L, 91L, 38L, 46L, 20L, 64L, 53L, 4L, 60L, 87L, 44L, 88L, 22L, 30L), 19L, 
          1060L
      )))
  
  }
  
  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 ];
    }