# Leetcode 1891.  Cutting Ribbons

```cpp
class Solution {
public:
    int maxLength(vector<int>& ribbons, int k) {
        long long sum = std::accumulate(ribbons.begin(), ribbons.end(), 0LL);
        int right_ptr = sum / k + 1;
        int left_ptr = 0;
        
        while (left_ptr < right_ptr) {
            int mid_ptr = (right_ptr - left_ptr) /2 + left_ptr;
            
            if (is_possible(mid_ptr, ribbons, k)) {
                left_ptr = mid_ptr + 1;
            }
            else {
                right_ptr = mid_ptr;
            }
        }
        
        return left_ptr - 1;
    }
    
    bool is_possible(int len, const vector<int>& ribbons, int k) {
        if (len == 0) return true;
        int accumulate_length = 0;
        
        for (const auto& ribbon : ribbons) {
            accumulate_length += ribbon / len;
            
            if (accumulate_length >= k) {
                return true;
            }
        }
        
        return false;
    }
};
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://unofficial-sendoh.gitbook.io/unofficialsendoh/c/l/leetcode-1891.-cutting-ribbons.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
