提交时间:2022-07-13 11:54:04
运行 ID: 51584
#include <bits/stdc++.h> using namespace std; const int N(510); struct Node{ int v,w;bool vis; }; int n,k; int e[N][N]; vector<Node> g[N << 1]; long long ans,sum1[N],sum2[N]; inline int read(){ register int x(0); register short w(1); register char c(getchar()); for (;c < '0' || c > '9';c = getchar()) if (c == '-') w = -1; for (;c >= '0' && c <= '9';c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); return x * w; } void Init(){ n = read(),k = read(); for (int i(1);i <= n;i++) for (int j(1);j <= n;j++){ int x(read()); if (i > j) g[i].push_back(Node{j,x}),g[j].push_back(Node{i,x}),e[i][j] = x; } return ; } void Solve(){ for (int i(1);i <= n;i++) for (int j(0);j < g[i].size();j++) sum1[i] += g[i][j].w,sum2[i] += (k - g[i][j].w); long long maxn(-1e9);int ind(0); for (int i(1);i <= n;i++) if (maxn < sum2[i]) maxn = sum2[i],ind = i; for (int i(1);i <= n;i++) for (int j(1);j <= n;j++) ans += e[i][j]; ans -= sum1[ind]; cout << ans + maxn; return ; } int main(){ Init();Solve(); return 0; }