title: Minimum Cost For Acquiring All Coins With K Extra Coins Allowed With Every Coin
signature: function minimum_cost_for_acquiring_all_coins_with_k_extra_coins_allowed_with_every_coin(coin, n, k)
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(coin, n, k, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(coin, n, 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({2, 4, 5, 9, 10, 10, 11, 14, 15, 19, 21, 22, 29, 36, 36, 38, 39, 39, 39, 41, 41, 42, 45, 45, 48, 55, 56, 57, 64, 66, 66, 66, 66, 69, 74, 76, 80, 81, 82, 82, 85, 87, 95, 95}, 33, 27, 2)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-98, -88, -52, -10, -6, 16, 20, 36, 48, 66, 68, 94}, 6, 10, 0)
      print(string.format("TEST-1...%s",result))
  
      result = driver({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}, 16, 16, 0)
      print(string.format("TEST-2...%s",result))
  
      result = driver({1, 4, 5, 6, 10, 11, 15, 24, 29, 32, 35, 43, 48, 49, 62, 71, 78, 91}, 13, 17, 0)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-98, -92, -88, -84, -82, -78, -74, -74, -68, -62, -62, -56, -56, -50, -46, -44, -26, -18, -14, -8, -8, -6, 8, 16, 20, 20, 22, 26, 36, 42, 44, 44, 52, 60, 66, 68, 68, 70, 76, 84}, 25, 34, 0)
      print(string.format("TEST-4...%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}, 32, 32, 0)
      print(string.format("TEST-5...%s",result))
  
      result = driver({5, 12, 38, 39, 52, 54, 62, 81, 87, 93}, 6, 8, 0)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-84, -76, -74, -70, -40, -32, -32, -26, -24, -18, -18, -12, -10, -8, 0, 4, 8, 16, 40, 40, 44, 60, 70, 86, 92, 94}, 25, 20, -84)
      print(string.format("TEST-7...%s",result))
  
      result = driver({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, 1, 1, 1, 1, 1, 1, 1}, 37, 29, 0)
      print(string.format("TEST-8...%s",result))
  
      result = driver({23, 31, 44, 56, 58, 61, 62, 63, 72, 74, 86, 97, 97, 98}, 12, 13, 0)
      print(string.format("TEST-9...%s",result))
  
  end
  
  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;
  }