class Solution {
public:
int largestSubmatrix(vector<vector<int>>& matrix) {
int R = matrix.size();
int C = matrix[0].size();
int result = 0;
for (int r = 1; r < R; ++r) {
auto& prevRow = matrix[r - 1];
auto& row = matrix[r];
for (int c = 0; c < C; ++c) {
if (row[c] != 0) row[c] += prevRow[c];
}
}
for (int r = 0; r < R; ++r) {
auto& row = matrix[r];
sort(row.begin(), row.end(), greater<int>());
for (int c = 0; c < C && row[c] > 0; ++c) {
result = max(result, (c + 1) * row[c]);
}
}
return result;
}
};