C++ solution
Code
# Code
```cpp []
class Solution {
public:
    int maxContainers(int n, int w, int maxWeight) {
        int totalCells = n*n;
        int totalWeight = totalCells*w;
        if(totalWeight <=maxWeight) {
            return totalCells;
        }
        
        while(totalWeight > maxWeight) {
            totalCells--;
            totalWeight -= w;
        }
        return totalCells;
    }
};
```
['C++']