title: Minimum Cost For Acquiring All Coins With K Extra Coins Allowed With Every Coin
signature: class Solution {
  
      public Integer minimumCostForAcquiringAllCoinsWithKExtraCoinsAllowedWithEveryCoin(ArrayList<Integer> coin, Integer n, Integer k) {
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.extension: java
question_info.entry_fn_name: minimumCostForAcquiringAllCoinsWithKExtraCoinsAllowedWithEveryCoin
question_info.entry_cls_name: Solution
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.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(ArrayList<Integer> coin, Integer n, Integer k, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(coin, n, k,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-98, -88, -52, -10, -6, 16, 20, 36, 48, 66, 68, 94)), 6, 10, 0);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(1, 4, 5, 6, 10, 11, 15, 24, 29, 32, 35, 43, 48, 49, 62, 71, 78, 91)), 13, 17, 0);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-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);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(5, 12, 38, 39, 52, 54, 62, 81, 87, 93)), 6, 8, 0);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-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);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(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);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(23, 31, 44, 56, 58, 61, 62, 63, 72, 74, 86, 97, 97, 98)), 12, 13, 0);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> coin, Integer n, Integer k, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(coin, n, k),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__