usingnamespacestd; inlineintread() { int X=0,w=0; char ch=0; while(!isdigit(ch)) {w|=ch=='-';ch=getchar();} while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); return w?-X:X; } constint maxn = 50050, INF = 12345634; structedge{ int to, cost, next; edge(int to = 0, int cost = 0, int next = 0):to(to), cost(cost), next(next){} }a[4 * maxn]; int head[maxn], ei = 0; voidadd_edge(int u, int v, int c){ a[ei] = edge(v, c, head[u]); head[u] = ei++; }
bool used[maxn]; int d[maxn];
voidMini(int &a, int b){ if (b < a) a = b; }
voidMaxi(int &a, int b){ if (b > a) a = b; }
intmain(){ memset(head, -1, sizeof(head)); int n_ = read(); int L = INF, R = -INF; // [L, R] for (int i = 0; i < n_; i++) { int a = read() + 1, b = read() + 1, c = read(); add_edge(b, a - 1, -c); Mini(L, a - 1); Maxi(R, b); } for (int i = L; i < R; i++) add_edge(i, i + 1, 1), add_edge(i + 1, i, 0); fill(d, d + R + 10, INF); d[R] = 0; queue<int> que; que.push(R); used[R] = true; while (!que.empty()){ int v = que.front(); que.pop(); used[v] = false;
for (int i = head[v]; i != -1; i = a[i].next) { int to = a[i].to, cost = a[i].cost; if (d[v] + cost < d[to]) { d[to] = d[v] + cost; if (!used[to]) que.push(to), used[to] = true; } } } printf("%d\n", -d[L]); }