2064. Minimized Maximum of Products Distributed to Any Store Medium

@problem@discussion
#Array#Binary Search



1/**
2 * [2064] Minimized Maximum of Products Distributed to Any Store
3 *
4 * You are given an integer n indicating there are n specialty retail stores. There are m product types of varying amounts, which are given as a 0-indexed integer array quantities, where quantities[i] represents the number of products of the i^th product type.
5 * You need to distribute all products to the retail stores following these rules:
6 * 
7 * 	A store can only be given at most one product type but can be given any amount of it.
8 * 	After distribution, each store will have been given some number of products (possibly 0). Let x represent the maximum number of products given to any store. You want x to be as small as possible, i.e., you want to minimize the maximum number of products that are given to any store.
9 * 
10 * Return the minimum possible x.
11 *  
12 * Example 1:
13 * 
14 * Input: n = 6, quantities = [11,6]
15 * Output: 3
16 * Explanation: One optimal way is:
17 * - The 11 products of type 0 are distributed to the first four stores in these amounts: 2, 3, 3, 3
18 * - The 6 products of type 1 are distributed to the other two stores in these amounts: 3, 3
19 * The maximum number of products given to any store is max(2, 3, 3, 3, 3, 3) = 3.
20 * 
21 * Example 2:
22 * 
23 * Input: n = 7, quantities = [15,10,10]
24 * Output: 5
25 * Explanation: One optimal way is:
26 * - The 15 products of type 0 are distributed to the first three stores in these amounts: 5, 5, 5
27 * - The 10 products of type 1 are distributed to the next two stores in these amounts: 5, 5
28 * - The 10 products of type 2 are distributed to the last two stores in these amounts: 5, 5
29 * The maximum number of products given to any store is max(5, 5, 5, 5, 5, 5, 5) = 5.
30 * 
31 * Example 3:
32 * 
33 * Input: n = 1, quantities = [100000]
34 * Output: 100000
35 * Explanation: The only optimal way is:
36 * - The 100000 products of type 0 are distributed to the only store.
37 * The maximum number of products given to any store is max(100000) = 100000.
38 * 
39 *  
40 * Constraints:
41 * 
42 * 	m == quantities.length
43 * 	1 <= m <= n <= 10^5
44 * 	1 <= quantities[i] <= 10^5
45 * 
46 */
47pub struct Solution {}
48
49// problem: https://leetcode.com/problems/minimized-maximum-of-products-distributed-to-any-store/
50// discuss: https://leetcode.com/problems/minimized-maximum-of-products-distributed-to-any-store/discuss/?currentPage=1&orderBy=most_votes&query=
51
52// submission codes start here
53
54impl Solution {
55    pub fn minimized_maximum(n: i32, quantities: Vec<i32>) -> i32 {
56        0
57    }
58}
59
60// submission codes end
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65
66    #[test]
67    fn test_2064() {
68    }
69}
70


Back
© 2025 bowen.ge All Rights Reserved.