2462. Total Cost to Hire K Workers
You are given a 0-indexed integer array costs
where costs[i]
is the cost of hiring the ith worker.
You are also given two integers k
and candidates
. We want to hire exactly k
workers according to the following rules:
k
sessions and hire exactly one worker in each session.candidates
workers or the last candidates
workers. Break the tie by the smallest index.
costs = [3,2,7,7,1,2]
and candidates = 2
, then in the first hiring session, we will choose the 4th worker because they have the lowest cost [3,2,7,7,1,2]
.[3,2,7,7,2]
. Please note that the indexing may be changed in the process.Return the total cost to hire exactly k
workers.
Example 1:
Example 2:
Constraints:
costs.length
<= 105costs[i]
<= 105k
, candidates
<= costs.length
不看 Discussion 根本看不懂這題在幹嘛= =
Ron ChenMon, Jun 26, 2023