思路题。看的题解。
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL __int64
LL p[];
int main()
{
int i,n,m,sv,ev,w;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(p,,sizeof(p));
for(i = ;i <= n;i ++)
{
scanf("%I64d",&p[i]);
p[i] = p[i]*;
}
for(i = ;i < m;i ++)
{
scanf("%d%d%d",&sv,&ev,&w);
p[sv] += w;
p[ev] += w;
}
sort(p+,p+n+);
LL ans = ;
for(i = ;i <= n;i ++)
{
if(i%)
ans -= p[i];
else
ans += p[i];
}
printf("%I64d\n",ans/);
}
return ;
}