emyeumeonhatF17
Member
Swift:
class Solution {
func minimizedMaximum(_ n: Int, _ quantities: [Int]) -> Int {
func check(_ max: Int) -> Bool {
var store = 0
for q in quantities {
store += (q + max - 1)/max // round up
if store > n { return false }
}
return store <= n
}
var low = 1
var high = quantities.max()!
while low < high {
let mid = (low + high)/2
if check(mid) {
high = mid
} else {
low = mid + 1
}
}
return low
}
}





bài này l <= r thì thành r = m - 1 thôi


