#include using namespace std; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector L(N); for(int i = 0; i < N; i++) { cin >> L[i]; } long long ans = 0; while(M--) { int F, B, W; cin >> F >> B >> W; auto it = lower_bound(L.begin(), L.end(), F); int add = B; if(it != L.end()) { add = max(add, W - (*it - F)); } if(it != L.begin()) { add = max(add, W - (F - *--it)); } ans += add; } cout << ans << '\n'; return 0; }