Easy BS on ANS (BEATS 100%)
IntuitionSo , we have to find the maximum number of candies a child can get and keep in mind that he gets it from a single pile.We have to maximize the number o
# Intuition
So , we have to find the maximum number of candies a child can get and keep in mind that he gets it from a single pile.We have to maximize the number of candies , so we can think of binary search on ans and the constraints also point towards the same.

# Approach
- Calculating the sum and dividing it by k , gives us the best  ans that may or may not be possible.
- This gives us the ending point for applying bs.
- So s=0 and e=sum/k;
- Now for each mid, we are trying to check if it is valid or not using the check function.
- If it is possible we are storing the ans and then searching for a better ans.

# Complexity
- Time complexity:
O(nlogn)

- Space complexity:
O(1)

# Code
```cpp []
class Solution {
public:
    bool check(long long mid,vector<int>& candies, long long k)
    {
        if(mid==0)
        return true;
        for(auto it:candies)
        {
            long long poss=it/mid;
            k-=poss;
            if(k<=0)
              return true;
        }
        return false;
    }
    int maximumCandies(vector<int>& candies, long long k) 
    {
        long long sum=accumulate(candies.begin(),candies.end(),0LL);
        sum=sum/k;
        long long s=0;
        long long e=sum;
        long long mid=s+(e-s)/2;
        long long ans=0;
        while(s<=e)
        {
            if(check(mid,candies,k))
            {
                ans=mid;
                s=mid+1;
            }
            else
            e=mid-1;
            mid=s+(e-s)/2;
        }
        return ans;
    }
};
```
['Binary Search', 'C++']