leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2064.cpp (466B)


      1 class Solution {
      2   public:
      3     int minimizedMaximum(const int n, const vector<int> &quantities) const {
      4         int low = 1, high = 100000;
      5 
      6         while (low <= high) {
      7             int mid = low + (high - low) / 2, count = 0;
      8             for (const int q : quantities)
      9                 count += (q + mid - 1) / mid;
     10 
     11             if (count <= n)
     12                 high = mid - 1;
     13             else
     14                 low = mid + 1;
     15         }
     16 
     17         return low;
     18     }
     19 };