ll n,a[2d5],b[2d5],c[2d5],d; segtree t; vector> v; { rd(n,(a,b,c)(n)); coordcomp(n,a); coordcomp(n,b); rep(i,n)b[i]*=-1; sortA(n,a,b,c); t.malloc(n+1,1); rep(i,n){ d=t.getMinVal(0,1-b[i])-c[i]; if(t.getMinVal(1-b[i],2-b[i])>d)t.change(1-b[i],2-b[i],d); } wt(-t.getMinVal(0,n+1)); }