#include <bits/stdc++.h> using namespace std; const int N = 1005; int n, m; struct account { double balance = 0; // 余额 double alert = 0; // 警戒值 } a[N]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i].balance; } double ans = 0; while (m--) { int x, y; double z; cin >> x >> y >> z; if (a[x].balance < z) break; int p = z; double sub = z - p; a[x].balance -= z; a[y].alert += sub; a[y].balance += p; ans += sub; if (a[y].alert > 1) break; } printf("%.2f", ans); return 0; }