标签:
开始写了一些东西但是后来浏览器挂了就没有存下来简直!!!!!!!!!!!!!QAQ
不想再写一遍了。。。总之是简单贪心。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #define MAXN 10005 7 using namespace std; 8 int n, m, a[MAXN], w, ans; 9 int main(){ 10 scanf("%d%d", &n, &m); 11 for(int i = 1; i <= n; i ++) { 12 scanf("%d", &w); ans -= w; a[i] += 2*w; 13 } 14 for(int i = 1; i <= m; i ++){ 15 int x, y, c; scanf("%d%d%d", &x, &y, &c); 16 ans -= c; a[x] += c; a[y] += c; 17 } 18 sort(a + 1, a + n + 1); 19 for(int i = n; i >= 1; i -= 2) ans += a[i]; 20 cout << ans << endl; 21 return 0; 22 }
标签:
原文地址:http://www.cnblogs.com/lixintong911/p/4995961.html