#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N; template class SegTree_1 { public: vector val; static V const def=0; V comp(V l,V r){ return max(l,r);}; SegTree_1(){val=vector(NV*2,def);}; V getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]); } }; SegTree_1 st; vector> E; void solve() { int i,j,k,l,r,x,y; string s; cin>>N; vector B; B.push_back(0); FOR(i,N) { cin>>x>>y>>r; E.push_back({-x,y,r}); B.push_back(y); } sort(ALL(B)); B.erase(unique(ALL(B)),B.end()); sort(ALL(E)); ll ma=0; FORR(e,E) { y=lower_bound(ALL(B),e[1])-B.begin(); ll a=st.getval(y+1,1<<19); st.update(y,a+e[2]); ma=max(ma,a+e[2]); } cout<