BackmediumUncategorized uncategorized medium

Minimize Maximum Task Execution Time Solution

Problem Statement

You are given an integer array `costs` of length `n`, where `costs[i]` represents the time multiplier for the `i`-th processor to process a single task. You are also given an integer `k` representing the total number of tasks to be distributed. You must distribute all `k` tasks among the `n` processors such that each processor is assigned a non-negative integer number of tasks, and the sum of tasks assigned to all processors is exactly `k`. If processor `i` is assigned $x_i$ tasks, its total execution time is $x_i \times \text{costs}[i]$. Return the minimum possible maximum execution time among all processors after an optimal distribution of tasks.

Example 1
Input
speedLimits = [2, 3, 5], vehiclesPerHour = 11
Output
6

Explanation: To minimize the maximum time taken in any lane, we distribute vehicles such that the maximum load is minimized. Using binary search, the minimum maximum load is 6 (Lane 1: 3 vehicles * 2s = 6s, Lane 2: 2 vehicles * 3s = 6s, Lane 3: 1 vehicle * 5s = 5s).

Constraints

  • 1 <= costs.length <= 10^5
  • 1 <= costs[i] <= 10^6
  • 0 <= k <= 10^9
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free