23.04.02 Today’s Leetcode
2300. Successful Pairs of Spells and Potions (medium)
class Solution:
def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:
dp = {}
def help(spell):
i = bisect_left(potions, success / spell)
return len(potions) - i
res = []
potions.sort()
# new_spells = sorted(spells)
for spell in spells:
res.append(help(spell))
return res
2410. Maximum Matching of Players With Trainers (medium)
class Solution:
def matchPlayersAndTrainers(self, players: List[int], trainers: List[int]) -> int:
players.sort()
trainers.sort()
i = j = 0
count = 0
while i < len(players) and j < len(trainers):
if players[i] <= trainers[j]:
count += 1
i += 1
j += 1
else:
j += 1
return count
826. Most Profit Assigning Work (medium)
class Solution:
def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:
d = {}
n = len(difficulty)
for i in range(n):
diff = difficulty[i]
if diff in d:
d[diff] = max(d[diff], profit[i])
else:
d[diff] = profit[i]
difficulty.sort()
worker.sort()
# print(difficulty)
# print(worker)
temp = -1
for diff in difficulty:
temp = max(temp, d[diff])
d[diff] = temp
res = 0
for p in worker:
i = bisect_right(difficulty, p) - 1
# print(i, difficulty[i])
if i == -1:
continue
res += d[difficulty[i]]
return res