1283.cpp (463B)
1 class Solution { 2 public: 3 int smallestDivisor(const vector<int> &nums, int threshold) const { 4 int left = 1, right = 1000000; 5 while (left < right) { 6 int mid = left + (right - left) / 2, sum = 0; 7 for (const int num : nums) 8 sum += (num + mid - 1) / mid; 9 if (sum > threshold) 10 left = mid + 1; 11 else 12 right = mid; 13 } 14 return left; 15 } 16 };