type
status
date
slug
summary
tags
category
icon
password
题目
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:- You will run
ksessions and hire exactly one worker in each session.
- In each hiring session, choose the worker with the lowest cost from either the first
candidatesworkers or the lastcandidatesworkers. Break the tie by the smallest index. - For example, if
costs = [3,2,7,7,1,2]andcandidates = 2, then in the first hiring session, we will choose the4thworker because they have the lowest cost[3,2,7,7,1,2]. - In the second hiring session, we will choose
1stworker because they have the same lowest cost as4thworker but they have the smallest index[3,2,7,7,2]. Please note that the indexing may be changed in the process.
- If there are fewer than candidates workers remaining, choose the worker with the lowest cost among them. Break the tie by the smallest index.
- A worker can only be chosen once.
Return the total cost to hire exactly
k workers.解题思路
两个小顶堆
C版本
Rust 版本
奇丑无比的 Rust 代码…,Rust还是写的太少了呀(´・_・`)
- 作者:Thomas He
- 链接:https://notion-next-lovat-ten.vercel.app/article/problems/leetcode/2462
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。