from bisect import bisect_left from collections import defaultdict N, M = map(int, input().split()) L = list(map(int, input().split())) L.sort() mi = L[0] ma = L[-1] d = defaultdict(int) for i in range(N): d[L[i]] += 1 ans = 0 for i in range(M): f, b, w = map(int, input().split()) if f in d: ans += w else: if f > ma: ans += max(w-abs(f-ma), b) elif mi > f: ans += max(w-abs(f-mi), b) else: e = bisect_left(L, f) ans += max(w-abs(L[e]-f), w-abs(L[e-1]-f), b) print(ans)