- var f,a,b,c,w,y:array[0..1000010]of int64;
- n,i,j,t,l,r,m:longint;
- ans:int64;
- procedure qs(l,r:longint);
- var i,j:longint;
- m,t:int64;
- begin
- i:=l; j:=r; m:=b[(l*3+r)>>2];
- repeat
- while b[i]<m do inc(i);
- while b[j]>m do dec(j);
- if i<=j then begin
- t:=a[i]; a[i]:=a[j]; a[j]:=t;
- t:=b[i]; b[i]:=b[j]; b[j]:=t;
- t:=c[i]; c[i]:=c[j]; c[j]:=t;
- inc(i); dec(j);
- end;
- until i>j;
- if l<j then qs(l,j);
- if i<r then qs(i,r);
- end;
- begin
- read(n);
- for i:=1 to n do
- read(a[i],b[i],c[i]);
- qs(1,n);
- t:=1; y[1]:=b[1]; w[1]:=c[1]; f[1]:=c[1];
- for i:=2 to n do begin
- l:=0; r:=t+1;
- while l+1<r do begin
- m:=(l+r)>>1;
- if y[m]>a[i] then r:=m
- else l:=m;
- end;
- f[i]:=w[l]+c[i];
- if f[i]>w[t] then begin
- inc(t); y[t]:=b[i]; w[t]:=f[i];
- end;
- end;
- writeln(w[t]);
- end.
来源: http://www.bubuko.com/infodetail-1948981.html