[C++] accepted solution || Binary Search || faster than 100%
\nclass Solution {\npublic:\n    int maximumCandies(vector<int>& candies, long long k) {\n        \n        long long sum=0;\n        \n        int n=candies.si
```\nclass Solution {\npublic:\n    int maximumCandies(vector<int>& candies, long long k) {\n        \n        long long sum=0;\n        \n        int n=candies.size();\n        \n        //calculate sum\n        for(int i=0;i<n;i++)\n        {\n            sum+=(long long)candies[i];\n        }\n        \n        \n        // if sum<k then we are not able to give a single one candy\n        if(sum<k) return 0;\n        \n        \n        long long h=sum/k;  // max possible ans cant exceed sum/k\n        long long l=1;      // min possible ans will be 1\n        long long res=1;\n        \n        \n        //next part is just binary search\n        while(h>=l)\n        {\n            long long m=(h+l)/2;\n            long long count=0;\n            for(int i=0;i<n;i++)\n            {\n                count+=candies[i]/m;\n            }\n            \n            if(count>=k)\n            {\n                res=max(res,m);\n                l=m+1;\n            }\n            else\n            {\n                h=m-1;\n            }\n        }\n        return res;\n        \n        \n    }\n};\n```\n**upvote**
['C', 'Binary Tree']