fork download
  1. /*
  2.  
  3. /**
  4.  * author: Phatsbell
  5.  * vnoi: https://o...content-available-to-author-only...i.info/user/ChiPhatNguyen
  6. **/
  7.  
  8.  
  9. #include <bits/stdc++.h>
  10. using namespace std;
  11. #define int long long
  12. #define pb push_back
  13. #define fi first
  14. #define se second
  15. #define all(v) (v).begin(), (v).end()
  16. #define rall(v) (v).rbegin(), (v).rend()
  17. #define sz(x) (int)(x).size()
  18. #define pii pair<int,int>
  19. const int INF = 1e18;
  20. const int MOD = 1e9+7;
  21. void fastIO(){
  22. ios::sync_with_stdio(0);
  23. cin.tie(0);
  24. }
  25. const int MAXN = 1005;
  26. int a[MAXN][MAXN], pref[MAXN][MAXN];
  27. main(){
  28. fastIO();
  29. int n, k;
  30. cin >> n >> k;
  31. for (int i = 1;i<=n;i++){
  32. for (int j = 1;j<=n;j++){
  33. cin >> a[i][j];
  34. }
  35. }
  36. for (int i = 1;i<=n;i++){
  37. for (int j = 1; j <= n; j++){
  38. pref[i][j] = a[i][j] + pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1];
  39. }
  40. }
  41. int ans = -INF;
  42. for (int i = k; i <= n; i++){
  43. for (int j = k; j <= n; j++){
  44. int sum = pref[i][j] - pref[i-k][j] - pref[i][j-k] + pref[i-k][j-k];
  45. ans = max(ans, sum);
  46. }
  47. }
  48. cout<<ans<<"\n";
  49. return 0;
  50. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
-1000000000000000000