fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 3e3 + 14;
  4. long long n, m, k, f[maxn][maxn], ans = 0;
  5. long long query(int i, int j){
  6. i --; j--;
  7. return f[i + k][j + k] - f[i][j + k] - f[i + k][j] + f[i][j];
  8. }
  9. void solve(){
  10. cin >> n >> m >> k;
  11. memset(f, 0, sizeof f);
  12. for (int i = 1; i <= n; i++){
  13. for (int j = 1; j <= m; j++) {
  14. long long x;
  15. cin >> x;
  16. f[i][j] = f[i - 1][j] + f[i][j - 1] + x - f[i - 1][j - 1];
  17. }
  18. }
  19. for (int i = 1; i <= n - k + 1; i++){
  20. for (int j = 1; j <= m - k + 1; j++){
  21. ans = max(ans, query(i,j));
  22. }
  23. }
  24.  
  25. cout << ans;
  26. }
  27. int main(){
  28. ios_base::sync_with_stdio(0);
  29. cin.tie(0); cout.tie(0);
  30. if (fopen("input.txt","r")) {
  31. freopen("input.txt","r",stdin);
  32. freopen("output.txt","w",stdout);
  33. }
  34. solve();
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0.01s 74576KB
stdin
0 0 0
stdout
Standard output is empty