rt,die码:
// # pragma GCC optimize("Ofast,no-stack-protector")
// # pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
int n, m, x, y, z, dis[30005];
vector <pii> v[30005];
bitset <30005> vis;
queue <int> q;
int main () {
ios::sync_with_stdio (0);
cin.tie (0);
cout.tie (0);
cin >> n >> m;
v[0].push_back ({1, 0});
for (int i = 1; i < n; ++ i)
v[i].push_back ({i + 1, 0}), v[i + 1].push_back ({i, -1});
while (m --) {
cin >> x >> y >> z;
v[x - 1].push_back ({y, z});
}
q.push (0);
while (! q.empty ()) {
x = q.front ();
q.pop ();
// cerr << x << ':' << dis[x] << '\n';
vis[x] = 0;
for (pii& i : v[x])
if (i.second + dis[x] > dis[i.first]) {
dis[i.first] = dis[x] + i.second;
if (! vis[i.first])
q.push (i.first), vis[i.first] = 1;
}
}
// for (int i = 1; i < n; ++ i) cout << dis[i] << ' ';
cout << dis[n];
return 0;
}