#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n, m; cin >> n >> m; vector l(n); for (int i = 0; i < n; i++) { cin >> l[i]; } long long ans = 0; for (int i = 0; i < m; i++) { int f; long long b, w; cin >> f >> b >> w; long long tmp = b; auto lb = lower_bound(l.begin(), l.end(), f); if (lb != l.end()) { tmp = max(tmp, w - (*lb - f)); } if (lb != l.begin()) { lb--; tmp = max(tmp, w - (f - *lb)); } ans += tmp; } cout << ans << endl; }