提交时间:2022-07-13 12:20:11
运行 ID: 51631
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll w[1003][1003]; ll Sub[1003],Add[1003]; int cnts,cnta; ll Read() { ll sum=0; char ch=getchar(); while(ch<'0' || ch>'9') ch=getchar(); while(ch>='0' && ch<='9') sum=sum*10+ch-'0',ch=getchar(); return sum; } int main() { ll n,k,d,val; n=Read(),k=Read(); d=(n*k+1)/2; ll Max=0,Min=1e7,Maxk,Mink; for(int i=1; i<=n; ++i) { for(int j=1; j<=n; ++j) w[i][j]=Read(),w[i][0]+=w[i][j]; if(w[i][0]<Min) Min=w[i][0],Mink=i; if(w[i][0]>Max) Max=w[i][0],Maxk=i; } for(int i=1; i<=n; ++i) { if( (w[i][0]<d && i!=Maxk) || i==Mink) Sub[++cnts]=i; if( (w[i][0]>=d && i!=Mink) || i==Maxk) Add[++cnta]=i; } for(int i=1; i<=cnta; ++i) for(int j=i; j<=cnta; ++j) Add[0]+=w[Add[i]][Add[j]]; //同 for(int i=1; i<=cnts; ++i) { for(int j=i; j<=cnts; ++j) Add[0]+=w[Sub[i]][Sub[j]]; //同 for(int j=1; j<=cnta; ++j) Sub[0]+=k-w[Sub[i]][Add[j]]; //异 } cout<<Add[0]+Sub[0]<<'\n'; return 0; }