#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
int n,k,a;
long long s[maxn][maxn],ans;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>k;
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j){
cin>>a;
s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a;
}
for(int i=k;i<=n;++i)
for(int j=k;j<=n;++j)
ans=max(ans,s[i][j]-s[i-k][j]+s[i-k][j-k]-s[i][j-k]);
cout<<ans;
return 0;
}
评论区