title: Minimum Cost For Acquiring All Coins With K Extra Coins Allowed With Every Coin
signature: minimum_cost_for_acquiring_all_coins_with_k_extra_coins_allowed_with_every_coin <- function(coin, n, k) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(coin, n, k, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(coin, n, k), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 4L, 5L, 9L, 10L, 10L, 11L, 14L, 15L, 19L, 21L, 22L, 29L, 36L, 36L, 38L, 39L, 39L, 39L, 41L, 41L, 42L, 45L, 45L, 48L, 55L, 56L, 57L, 64L, 66L, 66L, 66L, 66L, 69L, 74L, 76L, 80L, 81L, 82L, 82L, 85L, 87L, 95L, 95L), 33L, 27L, 
          2L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-98L, -88L, -52L, -10L, -6L, 16L, 20L, 36L, 48L, 66L, 68L, 94L), 6L, 10L, 
          0L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(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), 16L, 16L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(1L, 4L, 5L, 6L, 10L, 11L, 15L, 24L, 29L, 32L, 35L, 43L, 48L, 49L, 62L, 71L, 78L, 91L), 13L, 17L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-98L, -92L, -88L, -84L, -82L, -78L, -74L, -74L, -68L, -62L, -62L, -56L, -56L, -50L, -46L, -44L, -26L, -18L, -14L, -8L, -8L, -6L, 8L, 16L, 20L, 20L, 22L, 26L, 36L, 42L, 44L, 44L, 52L, 60L, 66L, 68L, 68L, 70L, 76L, 84L), 25L, 34L, 
          0L
      )))
  
      cat(sprintf("TEST-5...%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), 32L, 32L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(5L, 12L, 38L, 39L, 52L, 54L, 62L, 81L, 87L, 93L), 6L, 8L, 
          0L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-84L, -76L, -74L, -70L, -40L, -32L, -32L, -26L, -24L, -18L, -18L, -12L, -10L, -8L, 0L, 4L, 8L, 16L, 40L, 40L, 44L, 60L, 70L, 86L, 92L, 94L), 25L, 20L, 
          -84L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(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, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 37L, 29L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(23L, 31L, 44L, 56L, 58L, 61L, 62L, 63L, 72L, 74L, 86L, 97L, 97L, 98L), 12L, 13L, 
          0L
      )))
  
  }
  
  main()
source_py: def minimum_cost_for_acquiring_all_coins_with_k_extra_coins_allowed_with_every_coin(coin, n, k):
      coin.sort()
      coins_needed = math.ceil(((1.0 * n) // (k + 1)))
      ans = 0
      for i in range(((coins_needed - 1) + 1)):
          ans += coin[i]
      return ans
source_cpp: int minimum_cost_for_acquiring_all_coins_with_k_extra_coins_allowed_with_every_coin(vector<int> coin, int n, int k) {
    sort(coin.begin(), coin.end());
    int coins_needed = ceil ( 1.0 * n / ( k + 1 ) );
    int ans = 0;
    for ( int i = 0;
    i <= coins_needed - 1;
    i ++ ) ans += coin [ i ];
    return ans;
  }