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