思路题。看的题解。
1 #include <cstdio> 2 #include <string> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 #define LL __int64 7 LL p[100001]; 8 int main() 9 { 10 int i,n,m,sv,ev,w; 11 while(scanf("%d%d",&n,&m)!=EOF) 12 { 13 memset(p,0,sizeof(p)); 14 for(i = 1;i <= n;i ++) 15 { 16 scanf("%I64d",&p[i]); 17 p[i] = p[i]*2; 18 } 19 for(i = 0;i < m;i ++) 20 { 21 scanf("%d%d%d",&sv,&ev,&w); 22 p[sv] += w; 23 p[ev] += w; 24 } 25 sort(p+1,p+n+1); 26 LL ans = 0; 27 for(i = 1;i <= n;i ++) 28 { 29 if(i%2) 30 ans -= p[i]; 31 else 32 ans += p[i]; 33 } 34 printf("%I64d ",ans/2); 35 } 36 return 0; 37 }