提交时间:2022-07-13 11:53:36
运行 ID: 51576
#include<cstdio> typedef long long ll; int n; ll w[505][505],k,ans,sum; int main(){ // freopen("sub.in","r",stdin); // freopen("sub.out","w",stdout); scanf("%d%lld",&n,&k); for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) scanf("%lld",&w[i][j]); if(k==1){ printf("%d\n",(n-1)*(n-2)/2); return 0; } for(int i=1;i<=n;++i){ sum=0; for(int j=1;j<=n;++j){ if(j==i) continue; for(int l=1;l<j;++l){ if(l==i||j==l) continue; sum+=w[j][l]; } } for(int j=1;j<=n;++j){ ll res=sum; for(int l=1;l<=n;++l){ if(l==i||j==l) continue; res+=k-w[j][l]; } ans=ans>res?ans:res; } } printf("%lld\n",ans); }