fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. int m, n;
  7. cin >> m >> n;
  8. vector<vector<int>> a(m, vector<int>(n));
  9.  
  10. for (int i = 0; i < m; ++i)
  11. for (int j = 0; j < n; ++j)
  12. cin >> a[i][j];
  13.  
  14. int maxSum = 0;
  15.  
  16. for (int i = 0; i < m; ++i) {
  17. for (int j = 0; j < n; ++j) {
  18. int sum = 0;
  19. int x = i, y = j;
  20. while (x < m && y < n) {
  21. sum += a[x][y];
  22. x++;
  23. y++;
  24. }
  25. if (sum > maxSum) maxSum = sum;
  26. }
  27. }
  28.  
  29. cout << maxSum;
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0.01s 5316KB
stdin
3 4 
1 1 1 0
1 0 1 1
0 0 1 1
stdout
3