Copy Books
ID: 437; medium; 书籍复印
Solution 1 (Java)
Notes
The check of a feasible time here is crucial. Given a
time
, how do we know the minimum number of copiers needed to complete the job?If there is one book that takes longer than
time
to be copied, there is no way thistime
is feasible.Else in the general case, count the minimum number of copier needed. If this minimum number is larger than
k
, then thetime
is not feasible.
Solution 2 (Java)
Notes
We can further reduce the initial range by setting
left
to be the maximum page number andright
to be the sum of thepages
array. The reason is that the lower bound of the time is achieved by havingk = pages.length
and each person copies one book; the minimum time now would be the time to copy the book with largest page count. Then, the upper bound of the time is achieved by having only 1 copier to copy all the books by himself; so the time would be the sum of all the pages counts.Also, this solution uses a slightly different method to determine if time is feasible.
Last updated