C++ Binary Search Solution
Please Upvote If It Helps\n\nclass Solution {\npublic:\n    bool valid(int mid,vector<int>& candies,long long k)\n    {\n        // it will containg the count t
**Please Upvote If It Helps**\n```\nclass Solution {\npublic:\n    bool valid(int mid,vector<int>& candies,long long k)\n    {\n        // it will containg the count that will tell we can assign or not assign candies to children \n        long sum = 0;\n        for(auto it : candies)\n        {\n            sum += (it/mid);\n            \n            // if any time our sum is reches to k childrens it means we can assign so return true\n            if(sum>=k)\n                return true;\n        }\n        return false;\n    }\n    \n    int maximumCandies(vector<int>& candies, long long k) \n    {\n        // initializing two pointers onr for min one for max\n        // our answer lies between both of them it is final\n        long left  = 1;\n        long right = *max_element(begin(candies), end(candies));\n        \n        // applyting the binary search for searching that element\n        while(left<=right)\n        {\n            // deriving mid value\n            long mid = left+(right-left)/2;\n            \n            // if we can assign mid candies to k childrens successfully \n            // then can check for next bigger value\n            if(valid(mid,candies,k))\n            {\n                left = mid+1;\n            }\n            \n            // if we can not assign mid candies to k childrens successfully\n            // then can check for lesser value\n            else\n            {\n                right = mid-1;\n            }\n        }\n        return right;\n    }\n};\n```
[]