C++ || Binary Search On Answer || Explained || O(NlogN)
CONCEPT\n In these type of question first we have to find search space which is the possible set of answers which this question can have. Like in this case mini
**CONCEPT**\n* In these type of question first we have to find search space which is the possible set of answers which this question can have. Like in this case minimum answer can be zero and maximum can be maximum of the candies not more than that. \n* Simply apply binary search on this range [0,max] and if mid is possible answer than we will try to increase this answer by reducing our search space to [mid+1,max] else we will try to find answer in [0,mid].\n* isPossible function tells whether is it possible to divide the candies or not. So it is implemented greedily. So i have count the maximum number of children i can distribute candies to and if it is greater than equal to k than it is possible to divide else not.\n* Time:O(NlogN) and Space:O(1\n```\nclass Solution {\npublic:\n    bool isPossible(vector<int>& nums, long long k, long long mid){\n        long long cnt=0;\n        for(int i=0;i<nums.size();i++){\n            if(nums[i]>=mid){\n                cnt+=(nums[i]/mid);\n            }\n        }\n        return cnt>=k;\n    }\n    \n    \n    \n    int maximumCandies(vector<int>& candies, long long k) {\n        sort(candies.begin(),candies.end());\n        int n=candies.size();\n        long long sum=0;\n        int mx=INT_MIN;\n        for(int i=0;i<n;i++){\n            sum+=candies[i];\n            mx=max(mx,candies[i]);\n            \n        }\n        \n        long long l=1,r=mx;\n        int res=0;\n        while(l<=r){\n            long long mid=l+(r-l)/2;\n            if(isPossible(candies,k,mid)){\n                l=mid+1;\n            }else{\n                r=mid-1;\n            }\n        }\n        \n        return r;\n    }\n};\n```
['Binary Search', 'C']