#include #include #include #include #define llint long long #define inf 1e18 using namespace std; typedef pair P; struct SegTree{ int size; vector seg; SegTree(){} SegTree(int size){ this->size = size; seg.resize(1<<(size+1)); } void init() { for(int i = 0; i < (1<<(size+1)); i++) seg[i] = -inf; } void update(int i, llint val) { i += (1 << size); seg[i] = val; while(i > 1){ i /= 2; seg[i] = max(seg[i*2], seg[i*2+1]); } } llint query(int a, int b, int k, int l, int r) { if(b < l || r < a) return -inf; if(a <= l && r <= b) return seg[k]; llint lval = query(a, b, k*2, l, (l+r)/2); llint rval = query(a, b, k*2+1, (l+r)/2+1, r); return max(lval, rval); } llint query(int a, int b) { return query(a, b, 1, 0, (1< > vec; vector comp; SegTree seg(18); int main(void) { cin >> n; for(int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i]; for(int i = 0; i <= n; i++) comp.push_back(b[i]); sort(comp.begin(), comp.end()); comp.erase(unique(comp.begin(), comp.end()), comp.end()); for(int i = 1; i <= n; i++) b[i] = lower_bound(comp.begin(), comp.end(), b[i]) - comp.begin(); for(int i = 1; i <= n; i++) vec.push_back(make_pair(make_pair(a[i], -b[i]), c[i])); sort(vec.begin(), vec.end()); seg.init(); seg.update(0, 0); for(int i = 0; i < vec.size(); i++){ int p = -vec[i].first.second; seg.update(i+1, max(seg.query(p, p), seg.query(0, p-1) + vec[i].second) ); } cout << seg.query(1, vec.size()) << endl; return 0; }