fork download
  1. #include <bits/stdc++.h>
  2. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  3. #define el '\n'
  4. #define fi first
  5. #define se second
  6. #define ll long long
  7. #define pb push_back
  8. #define pf push_front
  9. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  10.  
  11. using namespace std;
  12.  
  13. signed main()
  14. {
  15.  
  16. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  17.  
  18. int n, k; cin >> n >> k;
  19. int p[n+1][n+1];
  20.  
  21. for (int i=0; i<=n; i++) p[i][0] = p[0][i] = 0;
  22.  
  23. for (int i=1; i<=n; i++)
  24. for (int j=1; j<=n; j++) {
  25. int x; cin >> x;
  26. p[i][j] = p[i][j-1] + p[i-1][j] - p[i-1][j-1] + x;
  27. }
  28.  
  29. int res = 0;
  30.  
  31. for (int i=k; i<=n; i++)
  32. for (int j=k; j<=n; j++)
  33. res = max(res, p[i][j] - p[i-k][j] - p[i][j-k] + p[i-k][j-k]);
  34.  
  35. cout << res;
  36.  
  37.  
  38.  
  39. return (0 ^ 0);
  40. }
Success #stdin #stdout 0.01s 5300KB
stdin
4 3
1 9 1 1 
9 9 9 9
9 9 9 9
14 9 9 1
stdout
86