| 2 | #include <algorithm> |
| 3 | |
| 4 | int cuttingWood(std::vector<int>& heights, int k) { |
| 5 | int left = 0; |
| 6 | int right = *std::max_element(heights.begin(), heights.end()); |
| 7 | while (left < right) { |
| 8 | // Bias the midpoint to the right during the upper-bound binary |
| 9 | // search. |
| 10 | int mid = (left + right) / 2 + 1; |
| 11 | if (cutsEnoughWood(mid, k, heights)) { |
| 12 | left = mid; |
| 13 | } else { |
| 14 | right = mid - 1; |
| 15 | } |
| 16 | } |
| 17 | return right; |
| 18 | } |
| 19 | |
| 20 | // Determine if the current value of 'H' cuts at least 'k' meters of |
| 21 | // wood. |
nothing calls this directly
no test coverage detected