inlineintread(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -x; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
constint MAXN = 10000 + 10;
int n, m; int wt[MAXN];
intmain(){ n = read(); m = read(); for (int i = 1; i <= n; ++i) { wt[i] = ((read()) << 1); // 一会要把边权均分到两条边里 // 为了避免除以二 这里先乘二 最后再除以二 } for (int i = 1; i <= m; ++i) { int a = read(); int b = read(); int c = read(); // 将边权均分到两条边中 wt[a] += c; wt[b] += c; } std::sort(wt + 1, wt + 1 + n, std::greater<int>()); longlongint ans = 0; for (int i = 1; i <= n; i += 2) { ans += wt[i] - wt[i + 1]; } printf("%lld\n", (ans) >> 1); return0; }