binary Search of Koko's type||15 ms Beats 95.45%
IntuitionAgain binary search of Koko's type
C++ & Python are doneApproach

bool f(vector<int>& nums, int n, int k, int cap) is defined to judge whether the robb
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Again binary search of Koko's type
C++ & Python are done
# Approach
<!-- Describe your approach to solving the problem. -->
1. `bool f(vector<int>& nums, int n, int k, int cap)` is defined to judge whether the robber can steal `at least from  k` houses with capability `cap`.

2. For shranking the search range, set `l=m r= M` where `m, M=ninmax(nums)`

3. It's to note during the loop `while(l<r){...}`, when `r=m, l=m+1` is used **the lower mid should be taken**

Very similar to solve [875. Koko Eating Bananas](https://leetcode.com/problems/koko-eating-bananas/solutions/3685871/w-explanation-easy-binary-search-c-solution/)
[Please turn on the English subtitles]
[https://youtu.be/KtZOZ4E1zww?si=o3rhF07qrvaTJn1z](https://youtu.be/KtZOZ4E1zww?si=o3rhF07qrvaTJn1z)
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
$O(n\log(M-m))$ where m, M= ninmax(nums)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
$O(1)$
# Code||15 ms Beats 95.45%
```cpp []
class Solution {
public:
    inline static bool f(vector<int>& nums, int n, int k, int cap){
        int steal=0;
        for(int i=0; i<n && steal<=k; i++){
            if (nums[i]<=cap){
                steal++;
                i++;
            }
        }
        return steal>=k;
    }
    static int minCapability(vector<int>& nums, int k) {
        const int n=nums.size();
        auto [min, max]=minmax_element(nums.begin(), nums.end());
        int l=*min, r=*max, m;
        while(l<r){
            m=(l+r)/2;
            if (f(nums, n, k, m))
                r=m;
            else
                l=m+1;
        }
        return l;
    }
};
```
```Python []
class Solution:
    def minCapability(self, nums: List[int], k: int) -> int:
        n=len(nums)
        x0=min(nums)
        xM=max(nums)
        def f(cap):
            steal, i=0, 0
            while i<n and steal<=k:
                if nums[i]<=cap:
                    steal+=1
                    i+=1
                i+=1
            return steal>=k

        l, r=x0, xM
        while l<r:
            m=(l+r)>>1
            if f(m):
                r=m
            else:
                l=m+1
        return l
        
```
['Binary Search', 'C++', 'Python3']