#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const int inf=1<<30; const ll INF=1LL<<62; typedef pair P; typedef pair PP; const ll MOD=998244353; int main(){ int N,M; cin>>N>>M; vector L(N); for(int i=0;i>L[i]; sort(L.begin(),L.end()); vector F(M),B(M),W(M); vector d(M); ll cost=0; for(int i=0;i>F[i]>>B[i]>>W[i]; cost+=B[i]; d[i]=W[i]-B[i];//水中だと+d[i]の強さ } for(int i=0;i=0){ cost+=d[i]-dist; } } cout<