题面
https://www.luogu.org/problem/P4643
题解
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; int n,m,a[10500]; bool cmp(int x,int y){ return x>y; } int main(){ int i,u,v,w; scanf("%d %d",&n,&m); for (i=1;i<=n;i++) { scanf("%d",&a[i]); a[i]<<=1; } for (i=1;i<=m;i++) { scanf("%d %d %d",&u,&v,&w); a[u]+=w; a[v]+=w; } sort(a+1,a+n+1,cmp); int tz=0,al=0; for (i=1;i<=n>>1;i++) { tz+=a[2*i-1]; al+=a[2*i]; } cout<<((tz-al)>>1); }