Untitled
unknown
plain_text
9 months ago
1.2 kB
10
Indexable
def maxMaintainedRepos(resolved: list[int], required: list[int], k: int) -> int:
"""
Calculates the maximum number of repositories that can be marked as maintained
by optimally distributing k issue resolutions.
"""
n = len(resolved)
# 1. Calculate the 'need' for each repository
# needed[i] = max(0, required[i] - resolved[i])
needs = []
# Repositories already maintained
maintained_count = 0
for i in range(n):
need = required[i] - resolved[i]
if need <= 0:
# Repository is already maintained (resolved[i] >= required[i])
maintained_count += 1
else:
# Repository needs 'need' more fixes
needs.append(need)
# 2. Filter and Sort the positive needs in ascending order
# We want to fix the cheapest repositories first
needs.sort()
# 3. Spend Greedily
for need in needs:
if k >= need:
# We have enough fixes to maintain this repository
k -= need
maintained_count += 1
else:
# Not enough fixes for this one (or any remaining, since they are sorted)
break
return maintained_countEditor is loading...
Leave a Comment