#include <stdio.h>
int main()
{
puts("转载请注明出处[vmurder]谢谢");
puts("网址:blog.csdn.net/vmurder/article/details/44499259");
}
PoPoQQQ大爷已经说得很详细了。
http://blog.csdn.net/PoPoQQQ/article/details/44495319
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 10100
using namespace std;
int n,m;
long long ans,x[N];
int main()
{
int i,j,k;
int a,b,c;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%d",&a);
ans-=a;x[i]=a<<1;
}
while(m--)
{
scanf("%d%d%d",&a,&b,&c);
ans-=c,x[a]+=c,x[b]+=c;
}
sort(x+1,x+n+1);
for(i=2;i<=n;i+=2)ans+=x[i];
cout<<ans<<endl;
return 0;
}
原文地址:http://blog.csdn.net/vmurder/article/details/44499259