- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have an array called jobs, where jobs[i] indicates the amount of time needed to complete the ith job. We also have another value k, to them we can assign jobs. Each job should be assigned to exactly one worker. And the working time of a worker is the total time it takes to complete all jobs assigned to them. We have to find the minimum possible maximum working time of any assignment.

So, if the input is like jobs = [2,1,3,8,5], k = 2, then the output will be 10 because, we can assign jobs like:

Worker1: 2 + 5 + 3 = 10

Worker2: 1 + 8 = 9

So maximum time is 10.

To solve this, we will follow these steps −

sort the list jobs in reverse order

assign := list of first k jobs

jobs := list of remaining jobs

Define a function dp() . This will take i, assign

if i is same as size of jobs , then

return maximum of assign

ans := infinity

for x in range 0 to k - 1, do

assign := a new list from assign

assign[x] := assign[x] + jobs[i]

ans := minimum of ans and dp(i+1, assign)

assign[x] := assign[x] - jobs[i]

return ans

from the main method return dp(0, assign)

Let us see the following implementation to get better understanding

def solve(jobs, k): jobs.sort(reverse=True) assign = tuple(jobs[:k]) jobs = jobs[k:] def dp(i, assign): if i == len(jobs): return max(assign) ans = float('inf') for x in range(k): assign = list(assign) assign[x] += jobs[i] ans = min(ans, dp(i+1, tuple(assign))) assign[x] -= jobs[i] return ans return dp(0, assign) jobs = [2,1,3,8,5] k = 2 print(solve(jobs, k))

[2,1,3,8,5], 2

10

- Related Questions & Answers
- Find minimum time to finish all jobs with given constraints in Python
- Find minimum time to finish all jobs with given constraints in C++
- Find minimum speed to finish all Jobs in C++
- Program to find maximum time to finish K tasks in Python
- Program to find minimum time to complete all tasks in python
- Program to find minimum cost to connect all points in Python
- Program to Find Out the Minimum Cost to Purchase All in Python
- Program to find minimum sum of difficulties to complete jobs over k days in C++
- Program to find minimum swaps needed to group all 1s together in Python
- Program to find out the minimum path to deliver all letters in Python
- Program to find minimum bus fare for travelling all days in Python?
- Program to find minimum number of vertices to reach all nodes using Python
- Program to find minimum amount needed to be paid all good performers in Python
- Program to find minimum time required to complete tasks with k time gap between same type tasks in Python
- Program to Find Out the Number of Moves to Reach the Finish Line in Python

Advertisements