Leetcode 853 Solution
This article provides solution to leetcode question 853 (most-profit-assigning-work)
Access this page by simply typing in "lcs 853" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/most-profit-assigning-work
Solution
class Solution:
def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:
a = []
for d, p in sorted(zip(difficulty, profit)):
if not a or a[-1][1] < p:
a.append((d, p))
ans = 0
for w in worker:
l = 0
r = len(a) - 1
while l < r:
m = (l + r + 1) // 2
if a[m][0] > w:
r = m - 1
else:
l = m
ans += a[l][1] if a[l][0] <= w else 0
return ans