typedef long long ll; typedef long double ld; #include using namespace std; #define int long long signed main(){ ll n,m; std::cin >> n>>m; vector lake(n); for (int i = 0; i < n; i++) { std::cin >> lake[i]; } ll ans = 0; for (int i = 0; i < m; i++) { ll f,b,w; std::cin >> f>>b>>w; ll dis = 1e18; auto it = lower_bound(lake.begin(),lake.end(),f); if(it!=lake.end()){ dis = min(dis, abs(*it-f)); } if(it!=lake.begin()){ it--; dis = min(dis, abs(*it-f)); } ans += max(b, w-dis); } std::cout << ans << std::endl; };