#include #include #include #include #include #include #include #include #define ll long long using namespace std; int main() { ll n, m; cin >> n >> m; vector pohon(n); for (int i = 0; i < n; i++) cin >> pohon[i]; ll score = 0; for (int i = 0; i < m; i++) { ll f, b, w; cin >> f >> b >> w; ll ansdist = 1e9 + 7; ll l = 0, r = n-1; while (l <= r) { int mid = l + (r - l) / 2; ll dist = pohon[mid] - f; if (abs(dist) <= ansdist) ansdist = abs(dist); if (dist == 0) { ansdist = 0; break; } else if (dist < 0) { l = mid + 1; } else if (dist > 0) { r = mid - 1; } } ll profit = w - b; if (profit > ansdist) { score += (w - ansdist); } else score += b; } cout << score << endl; return 0; }