# 一番近い水までの距離を見て一匹ずつどうするか決めればいいか # bisect N, M = map(int, input().split()) INF = 10**20 L = [-INF]+list(map(int, input().split()))+[INF] from bisect import * ans = 0 for i in range(M): f, b, w = map(int, input().split()) lower = L[bisect_left(L, f)-1] higher = L[bisect_left(L, f)] d = min(higher-f, f-lower) if d == 0: calc = w else: calc = max(b, w-d) ans += calc #print(f, lower, higher, d, calc) print(ans)