#include using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n,m; cin>>n>>m; vector l(n),f(m),b(m),w(m); for (int i=0;i>l[i]; for (int i=0;i>f[i]>>b[i]>>w[i]; sort(l.begin(),l.end()); long long ans=0; for (int i=0;i=b[i]) { ans+=get; continue; } if (idx>0) { idx--; long long get2=w[i]-abs(f[i]-l[idx]); if (get2>=b[i]) { ans+=get2; continue; } } ans+=b[i]; } cout<