// Source: https://usaco.guide/general/io #include using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int times = 1; while(times--){ ll n, m; cin >> n >> m; set s; for(int i = 0 ; i < n ; i++){ ll temp; cin >> temp; s.insert(temp); } ll answer = 0; for(int i = 0 ; i < m ; i++){ ll f, b, w; cin >> f >> b >> w; auto e = s.lower_bound(f); auto r = e; if(e == s.end()) r--; if(e != s.begin()) e--; if(*r == f) answer += w; else answer += max(b, max(w - abs(f - *r), w - abs(f - *e))); } cout << answer << endl; } }