Skip to content

Commit 613bd19

Browse files
authored
Create 2064. Minimized Maximum of Products Distributed to Any Store
1 parent 985bb99 commit 613bd19

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
int check(int val, vector<int>& nums, int n) {
4+
int cnt = 0;
5+
for (int i = 0; i < nums.size(); i++) {
6+
cnt += (nums[i] + val - 1) / val;
7+
}
8+
return cnt;
9+
}
10+
11+
int minimizedMaximum(int n, vector<int>& quantities) {
12+
int h = 1e5;
13+
int l = 1;
14+
int ans = -1;
15+
16+
while (l <= h) {
17+
int mid = l + (h - l) / 2;
18+
if (check(mid, quantities, n) <= n) {
19+
ans = mid;
20+
h = mid - 1;
21+
} else {
22+
l = mid + 1;
23+
}
24+
}
25+
return ans;
26+
}
27+
};

0 commit comments

Comments
 (0)