Untitled
unknown
plain_text
5 months ago
1.1 kB
5
Indexable
def countMaximumDays(lend, payback): from bisect import bisect_left n = len(lend) # Create a list of lenders with their lend amount, index, and payback lenders = sorted([(lend[i], i, payback[i]) for i in range(n)]) day = 0 prev_payback = 0 # No payback on the first day while True: if day == 0: # On the first day, pick the lender with the smallest lend amount lend_i, idx, payback_i = lenders.pop(0) prev_payback = payback_i day += 1 else: # Need to find a lender with lend >= prev_payback # Extract the list of lend amounts lend_amounts = [l[0] for l in lenders] # Find the leftmost lender with lend >= prev_payback left = bisect_left(lend_amounts, prev_payback) if left == len(lenders): break # No lender can satisfy the payback requirement lend_i, idx, payback_i = lenders.pop(left) prev_payback = payback_i day += 1 if not lenders: break # No more lenders to borrow from return day
Editor is loading...
Leave a Comment