3492. Maximum Containers on a Ship Easy

@problem@discussion
#Math



1/**
2 * [3492] Maximum Containers on a Ship
3 *
4 * You are given a positive integer n representing an n x n cargo deck on a ship. Each cell on the deck can hold one container with a weight of exactly w.
5 * However, the total weight of all containers, if loaded onto the deck, must not exceed the ship's maximum weight capacity, maxWeight.
6 * Return the maximum number of containers that can be loaded onto the ship.
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">n = 2, w = 3, maxWeight = 15</span>
11 * Output: 4
12 * Explanation: 
13 * The deck has 4 cells, and each container weighs 3. The total weight of loading all containers is 12, which does not exceed maxWeight.
14 * </div>
15 * <strong class="example">Example 2:
16 * <div class="example-block">
17 * Input: <span class="example-io">n = 3, w = 5, maxWeight = 20</span>
18 * Output: <span class="example-io">4</span>
19 * Explanation: 
20 * The deck has 9 cells, and each container weighs 5. The maximum number of containers that can be loaded without exceeding maxWeight is 4.
21 * </div>
22 *  
23 * Constraints:
24 * 
25 * 	1 <= n <= 1000
26 * 	1 <= w <= 1000
27 * 	1 <= maxWeight <= 10^9
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/maximum-containers-on-a-ship/
33// discuss: https://leetcode.com/problems/maximum-containers-on-a-ship/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn max_containers(n: i32, w: i32, max_weight: i32) -> i32 {
39        0
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_3492() {
51    }
52}
53

Back
© 2026 bowen.ge All Rights Reserved.