title: Minimum Cost For Acquiring All Coins With K Extra Coins Allowed With Every Coin
signature: def minimumCostForAcquiringAllCoinsWithKExtraCoinsAllowedWithEveryCoin(coin: List[Int], n: Int, k: Int) = {
test_code: import scala.collection.mutable.HashMap
  import scala.collection.immutable.HashSet
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  
  // TESTING CODE 
  // ============================================
  def validateSolution(actual: Int , expected: Int): Boolean = {
      actual.toString == expected.toString
  }
  
  def driver(coin: List[Int], n: Int, k: Int, expected: Int): String = {
      try {
          if (validateSolution(PLACEHOLDER_FN_NAME(coin, n, k),expected)) {
              "PASSED"
          } else{
              "FAILED"
          }
      }catch{
          case e: Exception => {e.getClass.getName}
      }
  
  }
  object QuestionEvaluator extends App {
  
      println(s"TEST-0...${driver(
        List(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    
      )}")   
  
  
      println(s"TEST-1...${driver(
        List(-98, -88, -52, -10, -6, 16, 20, 36, 48, 66, 68, 94), 6, 10, 
        0    
      )}")   
  
  
      println(s"TEST-2...${driver(
        List(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    
      )}")   
  
  
      println(s"TEST-3...${driver(
        List(1, 4, 5, 6, 10, 11, 15, 24, 29, 32, 35, 43, 48, 49, 62, 71, 78, 91), 13, 17, 
        0    
      )}")   
  
  
      println(s"TEST-4...${driver(
        List(-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    
      )}")   
  
  
      println(s"TEST-5...${driver(
        List(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    
      )}")   
  
  
      println(s"TEST-6...${driver(
        List(5, 12, 38, 39, 52, 54, 62, 81, 87, 93), 6, 8, 
        0    
      )}")   
  
  
      println(s"TEST-7...${driver(
        List(-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    
      )}")   
  
  
      println(s"TEST-8...${driver(
        List(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    
      )}")   
  
  
      println(s"TEST-9...${driver(
        List(23, 31, 44, 56, 58, 61, 62, 63, 72, 74, 86, 97, 97, 98), 12, 13, 
        0    
      )}")   
  
  }
  
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;
  }