forked from Hrudhay-H/Cpp_Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetcode_3492.cpp
More file actions
27 lines (21 loc) · 831 Bytes
/
Leetcode_3492.cpp
File metadata and controls
27 lines (21 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
using namespace std;
class Solution {
public:
// Function to calculate the maximum number of containers that can be carried
int maxContainers(int n, int w, int maxWeight) {
// Check if the total possible containers (n*n) exceeds the weight capacity
return ((maxWeight / w) > n * n) ? n * n : (maxWeight / w);
}
};
int main() {
Solution obj; // Creating an instance of the Solution class
int n = 2; // Number of rows/columns of containers (assuming a square grid)
int w = 2; // Weight of each container
int maxWeight = 6; // Maximum weight that can be carried
// Calling the function to get the result
int result = obj.maxContainers(n, w, maxWeight);
// Printing the result
cout << result << endl;
return 0;
}