From “Koko eating bananas”:
1.lambda functions: Inline functions instead of declaring it outside of the main function, can reduce overhead from funtion calls.
[capture_list](parameters) -> return_type { function_body }
//capture_list 可以決定call by reference [&], value [=]||[]
auto good = [&](int x) {
long long hours = 0 ;
for(auto &i : piles) {
hours += (i+x-1)/x ;
}
return hours <= h ;
} ;
while(!(good(r))) r*= 2;
2.Exponential search
Instead of running binary search on the whole array, double the upper bound till we find the actual least upper bound.