title: Minimum Cost For Acquiring All Coins With K Extra Coins Allowed With Every Coin
signature: function minimumCostForAcquiringAllCoinsWithKExtraCoinsAllowedWithEveryCoin(coin: Array<number>, n: number, k: number): number {
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;
  }
question_info.test_list: [{"idx": 0, "outputs": 2, "inputs": {"coin": [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], "n": 33, "k": 27}}, {"idx": 1, "outputs": 0, "inputs": {"coin": [-98, -88, -52, -10, -6, 16, 20, 36, 48, 66, 68, 94], "n": 6, "k": 10}}, {"idx": 2, "outputs": 0, "inputs": {"coin": [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], "n": 16, "k": 16}}, {"idx": 3, "outputs": 0, "inputs": {"coin": [1, 4, 5, 6, 10, 11, 15, 24, 29, 32, 35, 43, 48, 49, 62, 71, 78, 91], "n": 13, "k": 17}}, {"idx": 4, "outputs": 0, "inputs": {"coin": [-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], "n": 25, "k": 34}}, {"idx": 5, "outputs": 0, "inputs": {"coin": [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], "n": 32, "k": 32}}, {"idx": 6, "outputs": 0, "inputs": {"coin": [5, 12, 38, 39, 52, 54, 62, 81, 87, 93], "n": 6, "k": 8}}, {"idx": 7, "outputs": -84, "inputs": {"coin": [-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], "n": 25, "k": 20}}, {"idx": 8, "outputs": 0, "inputs": {"coin": [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], "n": 37, "k": 29}}, {"idx": 9, "outputs": 0, "inputs": {"coin": [23, 31, 44, 56, 58, 61, 62, 63, 72, 74, 86, 97, 97, 98], "n": 12, "k": 13}}]
question_info.entry_cls_name: Solution
question_info.test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value: any): string{
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual: number, expected: number): boolean {
      return convertToString(actual) === convertToString(expected);
  }
  
  function driver(coin: Array<number>, n: number, k: number, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(coin, n, k),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    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);
    console.log(`TEST-0...${result}`);
  
    result = driver([-98, -88, -52, -10, -6, 16, 20, 36, 48, 66, 68, 94], 6, 10, 0);
    console.log(`TEST-1...${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);
    console.log(`TEST-2...${result}`);
  
    result = driver([1, 4, 5, 6, 10, 11, 15, 24, 29, 32, 35, 43, 48, 49, 62, 71, 78, 91], 13, 17, 0);
    console.log(`TEST-3...${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);
    console.log(`TEST-4...${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);
    console.log(`TEST-5...${result}`);
  
    result = driver([5, 12, 38, 39, 52, 54, 62, 81, 87, 93], 6, 8, 0);
    console.log(`TEST-6...${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);
    console.log(`TEST-7...${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);
    console.log(`TEST-8...${result}`);
  
    result = driver([23, 31, 44, 56, 58, 61, 62, 63, 72, 74, 86, 97, 97, 98], 12, 13, 0);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
question_info.extension: ts
question_info.entry_fn_name: minimumCostForAcquiringAllCoinsWithKExtraCoinsAllowedWithEveryCoin
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: tsc --target es2020 --lib es5,dom,es2015,es2020 __FILENAME__
question_info.commands: node __FILENAME__.js