Easy BinarySearch solution
Intuition

We want to maximize the number of candies each child gets while ensuring that at least k children receive them.


Since giving more candies means ser
# Intuition
1. We want to maximize the number of candies each child gets while ensuring that at least `k` children receive them.  

2. Since giving more candies means serving fewer children, we use **binary search** to efficiently find the largest valid number of candies per child.  

3. For each `mid` (possible candies per child), we check if distributing them to at least `k` children is possible, adjusting our search range accordingly.
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
1. Use **binary search** on the possible candy distribution range (`1` to `maxElement`) to find the maximum candies each child can get.  

2. For each mid-value, use the `check` function to count how many children can receive at least `mid` candies and verify if it's at least `k`.  

3. If possible, move `low` up to find a larger valid `mid`, otherwise move `high` down, and return the best found `mid` as the answer.

# Complexity
- Time complexity:O(n*log(maxelement in candies))
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
bool check(vector<int>&c,int mid,long long k)
{
    for(int i=0;i<c.size();i++)
    {
        k-=(c[i]/mid);
        if(k<=0)
        {
            return true;
        }

    }
    return false;
}
    int maximumCandies(vector<int>& c, long long k) {
        int n=c.size();
        int low=1;
        int high=*max_element(c.begin(),c.end());
        int ans=0;
        while(low<=high)
        {
            int mid=(low+high)>>1;
            if(check(c,mid,k))
            {
                ans=mid;
                low=mid+1;
            }
            else
            {
                high=mid-1;
            }
        }
        return ans;
    }
};
```
['Binary Search', 'C++']