-
-
Notifications
You must be signed in to change notification settings - Fork 100
2071. Maximum Number of Tasks You Can Assign #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reviewer's GuideThis PR adds a C++ solution for LeetCode problem 2071 by sorting tasks and workers, using a binary search over the number of tasks to assign, and a multiset-based greedy check function that allocates pills to boost workers’ strength when needed. Sequence diagram for the task assignment process with pillssequenceDiagram
participant Solution
participant "tasks[]"
participant "workers[]"
participant "multiset st"
participant "pills"
Solution->>tasks[]: Sort tasks ascending
Solution->>workers[]: Sort workers descending
loop Binary search for k (max tasks)
Solution->>multiset st: Select k strongest workers
loop For each of k easiest tasks (reverse order)
Solution->>multiset st: Find strongest available worker
alt Worker strength >= task requirement
Solution->>multiset st: Assign task, remove worker
else Pills available
Solution->>multiset st: Find weakest worker that can do task with pill
Solution->>pills: Use pill
Solution->>multiset st: Assign task, remove worker
else No worker can do task
Solution->>Solution: Return false for this k
end
end
Solution->>Solution: If all tasks assigned, k is feasible
end
Solution->>Solution: Return largest feasible k
Class diagram for Solution and helper methodsclassDiagram
class Solution {
+int maxTaskAssign(vector<int>& tasks, vector<int>& workers, int pills, int strength)
-bool check(vector<int>& tasks, vector<int>& workers, int pills, int strength, int mid)
}
Solution : check
Solution : maxTaskAssign
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 tasks
SjxSubham
approved these changes
Oct 16, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Intuition
We need to assign the maximum number of tasks to workers. Each worker has a strength, and we can give up to
pillsto temporarily increase their strength. The best strategy is to try assigning more tasks and check feasibility using a greedy approach.Approach
- If k is possible, try a larger k.
- If not, reduce k.
Code Solution (C++)
Related Issues
By submitting this PR, I confirm that:
Summary by Sourcery
New Features: