Binary Search method
class Solution {\npublic:\n    bool allocation(vector& candies,long long k,long long mid){\n        if(mid==0) return true;\n        \n        long long q=0;\n 
class Solution {\npublic:\n    bool allocation(vector<int>& candies,long long k,long long mid){\n        if(mid==0) return true;\n        \n        long long q=0;\n        long long count=0;\n         for(int i=0;i<candies.size();i++){\n            int q=candies[i]/mid;\n            count+=q;\n            if(count>=k){\n               return true;\n              }\n        }\n        \n        return false;\n        \n    }\n    \n    int maximumCandies(vector<int>& candies, long long k) {\n        \n        int ans=0;\n        for(int i=0;i<candies.size();i++){\n          ans=max(ans,candies[i]);\n        }  \n        long long low=0,high=ans;\n        while(low<high){\n            long long mid=(low+high)/2;\n            \n            if(allocation(candies,k,mid)){\n                low=mid+1;\n            }else{\n                high=mid;\n            }\n        }\n       \n       return allocation(candies,k,low)?low:low-1;\n        \n       \n        \n    }\n};
[]