Ctrl K

Best-Paid Gig for Each Worker

Medium
A gig board lists n kinds of gigs: gig i requires a level of at least levels[i] and pays pay[i]. There are m workers, and worker j has skill skills[j], so they can handle any gig whose level does not exceed their skill. Each worker takes at most one gig, while the same gig can be done by any number of workers, each getting the full pay. A worker with no suitable gig earns 0. Return the largest possible total earnings of all workers.
Example 1
levels=[3, 1, 5], pay=[30, 12, 25], skills=[2, 4, 6] → 72

The worker with skill 2 takes the level-1 gig (12), the one with skill 4 takes the level-3 gig (30), and the one with skill 6 also prefers level 3 (30) over level 5 (25). Total 12 + 30 + 30 = 72.

Example 2
levels=[10, 20], pay=[5, 9], skills=[3, 8] → 0

No worker reaches even level 10, so nobody earns anything.

Example 3
levels=[2], pay=[7], skills=[2, 2, 9] → 21
Constraints
  • 1 ≤ n, m ≤ 10⁵
  • len(levels) = len(pay) = n, len(skills) = m
  • 1 ≤ levels[i], pay[i], skills[j] ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsStick Triples That Form a Triangle MediumMentor at Least Twice as Strong MediumFlowerbed Beauty on a Budget HardStudios for Recording Sessions MediumTriples Under a Limit Medium
loading Python…
Input
levels=[3, 1, 5], pay=[30, 12, 25], skills=[2, 4, 6]
Expected
72

Run checks the first 3 tests in your browser. Submit checks all 108 tests on the server, hidden ones included.