Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
617 B
7
Indexable
Never
def minimumNumberOfPages(pages, days):
    def totalDays(num_pages):
        total = 0
        for page_count in pages:
            total += (page_count + num_pages - 1) // num_pages
        return total
    
    low = 1
    high = max(pages)
    result = float('inf')
    
    while low <= high:
        mid = (low + high) // 2
        total = totalDays(mid)
        
        if total <= days:
            result = min(result, mid)
            high = mid - 1
        else:
            low = mid + 1
            
    if result == float('inf'):
        return -1
    else:
        return result
Leave a Comment