競賽程式設計簡單

完成工作的最短時間

「完成作業的最短時間」問題的詳細指南和 Python 實作。

問題陳述

簡單

寫一個函數 min_time_jobs(jobs, k, t) 來找出完成所有作業的最短時間。陣列 jobs 表示完成每個作業所需的時間。有 k 受讓人,每個受讓人花費 t 單位時間來完成 1 單位作業。作業只能作為連續的子段分配給受讓人。

約束條件
  • 1 <= len(jobs) <= 10^5
  • 1 <= k <= len(jobs)
  • 1 <= t <= 1000
  • 1 <= jobs[i] <= 10^4

範例

Example 1
Input
min_time_jobs([10, 7, 8, 12, 8, 5, 9], 4, 5)
Output
100
Explanation

Optimal contiguous assignment: [10, 7], [8, 12], [8, 5], [9]. Max job units assigned is 20 (8+12). Time = 20 * 5 = 100.

Example 2
Input
min_time_jobs([4, 5, 10], 2, 1)
Output
10
Explanation

Optimal contiguous assignment: [4, 5], [10]. Max job units assigned is 10. Time = 10 * 1 = 10.

Need a Hint?
考慮使用特定於貪婪的資料結構,例如集合或堆疊。
Edge Cases to Watch
  • 空輸入結構
  • 單元素輸入
  • 大數值範圍

準備好解決了嗎?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

在編輯器中開啟
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

推薦的 Python 資源

透過相關的互動式教學、備忘單和程式碼比較來擴展您的知識。