提交时间:2022-07-13 11:52:20
运行 ID: 51554
#include<bits/stdc++.h> #define il inline #define ll long long using namespace std; const int maxn=510; il int read(){ int x=0; char c=getchar(); for(;!(c>='0'&&c<='9');c=getchar()); for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+c-'0'; return x; } int n,K,a[maxn][maxn]; ll Solve(int x,int y,ll sum=0){ for(int i=1;i<=n;sum-=a[y][i],i++) if((y^i)&&(x^i)) sum+=K-a[x][i]; return sum; } int main(){ ll sum=0,ans=0; n=read(),K=read(); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) a[i][j]=read(),sum+=a[i][j]; sum>>=1; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) ans=max(Solve(i,j)+sum,ans); printf("%lld\n",ans); return 0; }