fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define el "\n"
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define se second
  7. #define fi first
  8. #define be begin()
  9. #define en end()
  10. #define Faster cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
  11. int main()
  12. {
  13. Faster;
  14. int n, m; cin >> n >> m;
  15. int a[n][m];
  16. for(int i = 0; i < n; i++)
  17. {
  18. for(int j = 0; j < m; j++)
  19. {
  20. cin >> a[i][j];
  21. }
  22. }
  23. int ans = INT_MIN;
  24. for(int i = 0; i < n - 1; i++)
  25. {
  26. for(int j = 0; j < m - 1; j++)
  27. {
  28. int tmp = 0;
  29. for(int x = i; x < i + 2; x++)
  30. {
  31. for(int y = j; y < j + 2; y++)
  32. {
  33. tmp += a[x][y];
  34. }
  35. }
  36. ans = max(ans, tmp);
  37. }
  38. }
  39. cout << ans;
  40. }
  41.  
Success #stdin #stdout 0.01s 5280KB
stdin
4 5
1 1 0 0 0
-2 0 0 0 0
0 0 1 1 0
0 0 1 1 0
stdout
4