#include "bits/stdc++.h" using namespace std; #pragma warning(disable:4996) #define Seg_Max_N (1<<18) using Value = long long int; const Value ini =0; struct segtree { int N; vectordat; segtree() {} segtree(int n) :dat(2 * Seg_Max_N) { N = 1; while (N < n) N *= 2; for (int i = 0; i < 2 * N - 1; i++) { dat[i] = ini; } } Value connect(const Value&l, const Value&r) { return max(l,r); } // update k th element void update(int k, Value a) { k += N - 1; dat[k] = a; while (k > 0) { k = (k - 1) / 2; const Value al(dat[k * 2 + 1]); const Value ar(dat[k * 2 + 2]); dat[k] = connect(al, ar); } } // min [a, b) Value query(int a, int b) { return query(a, b, 0, 0, N); } Value query(int a, int b, int k, int l, int r) { if (r <= a or b <= l) return ini; if (a <= l and r <= b) return dat[k]; const int m = (l + r) / 2; const Value al(query(a, b, k * 2 + 1, l, m)); const Value ar(query(a, b, k * 2 + 2, m, r)); return connect(al, ar); } }; struct cake { int a; int b; long long int c; }; bool operator<(const cake&l, const cake&r) { return l.a struct Compress { mapmp; maprevmp; Compress(vectorvs) { setmp(vs); } Compress() :mp(), revmp() { } void setmp(vectorvs) { sort(vs.begin(), vs.end()); vs.erase(unique(vs.begin(), vs.end()), vs.end()); for (int i = 0; i < static_cast(vs.size()); ++i) { mp[vs[i]] = i; revmp[i] = vs[i]; } } }; int main() { int N;cin>>N; vectorcakes(N); vectorbs{ 0 }; for (int i = 0; i < N; ++i) { int a,b; long long int c; scanf("%d %d %lld",&a,&b,&c); bs.push_back(b); cakes[i] = cake{ a,b,c }; } Compress cb(bs); sort(cakes.begin(),cakes.end()); segtree seg(N+1); seg.update(0,0); for (int i = 0; i < N; ++i) { long long int num=seg.query(0,cb.mp[cakes[i].b]); seg.update(cb.mp[cakes[i].b],max(seg.query(cb.mp[cakes[i].b],cb.mp[cakes[i].b]+1),num+cakes[i].c)); } long long int answer=seg.query(0,N+1); cout<