fork download
  1. // Online C++ compiler to run C++ program online
  2. #include <iostream>
  3. #include <bits/stdc++.h>
  4.  
  5. #define ll long long
  6. #define endll '\n'
  7. #define FOR for(int i = 1; i <= n; i++)
  8. using namespace std;
  9. void fastIO()
  10. {
  11. ios_base::sync_with_stdio(false);
  12. cin.tie(NULL);
  13. cout.tie(NULL);
  14. }
  15. ll a[1001][1001];
  16. int main() {
  17. fastIO();
  18. int n , m; cin >> n >> m;
  19. for(int i = 1; i <= n; ++i)
  20. {
  21. for(int j = 1; j <= m ; ++j)
  22. {
  23. cin >> a[i][j];
  24. }
  25. }
  26.  
  27.  
  28. for(int i = 1; i <= n; ++i)
  29. {
  30. for(int j = 1; j <= m ; ++j)
  31. a[i][j] += a[i][j - 1];
  32. }
  33.  
  34. for(int i = 1; i <= m; ++i)
  35. {
  36. for(int j = 1; j <= n ; ++j)
  37. a[j][i] += a[j - 1][i];
  38. }
  39.  
  40.  
  41. int x,y; cin >> x >> y;
  42.  
  43. ll mx = LLONG_MIN;
  44. for (int down = x; down <= n; ++down )
  45. {
  46. for(int right = y; right <= m; ++right)
  47. {
  48. int left = right - y + 1;
  49. int up = down - x + 1;
  50. mx = max(mx, a[down][right] - a[up-1][right] - a[down][left-1] + a[up - 1][left - 1]);
  51. }
  52. }
  53. cout << mx << endll;
  54. return 0;
  55. }
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
-9223372036854775808