🌟🔥Best Solution in C++ || BinarySearch on Answer🔥💯
Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(1)\n\n# Code\nPlease Upvote if u liked my Solution\uD83E\uDD17\n\nclass Solution {\npublic:\n
# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(1)\n\n# Code\n**Please Upvote if u liked my Solution**\uD83E\uDD17\n```\nclass Solution {\npublic:\n    bool occurrences(int x,vector<int>& candies,long k){\n        long ans=0;\n        for(auto it:candies){\n            ans+=it/x;\n            if(ans>=k)\n                return true;\n        }\n        return false;\n    }\n    int maximumCandies(vector<int>& candies, long long k) {\n        int size=candies.size(),ans=-1;\n        long sum=0;\n        for(auto it:candies)\n            sum+=it;\n        if(sum<k)\n            return 0;\n        int ll=1,ul=sum/k,mid;\n        while(ll<=ul){\n            mid= (ll+ul) >> 1;\n            if(occurrences(mid,candies,k)){\n                ans=mid;\n                ll=mid+1;\n            }\n            else\n                ul=mid-1;\n        }\n        return ans;\n    }\n};\n```
['Array', 'Binary Search', 'C++']