M
mikelhpdatke
Mình sẽ giải trước bài hội trường, mấy bài kia mai post sau
Mã:
Program HoiTruong;
Var A,B,C,F:array[0..100000] Of Integer;
D:array[0..100000] Of Boolean;
N,i,j,k:integer;
Procedure Init;
Begin
Readln(n);
For i:=1 to n do
Begin
Readln(A[i], B[i]);
C[i]:=B[i]-A[i];
End;
FillChar(D,SizeOf(D),True);
//Writeln;
End;
Procedure Sapxep(L,H:integer);
Var i,j,k,t:integer;
Begin
If L>=H then exit;
k:=B[Random(H-L+1)+L];
i:=L;
j:=H;
Repeat
While B[i]<k do inc(i);
While B[j]>k do dec(j);
If i<=j then
Begin
t:=C[i];
C[i]:=C[j];
C[j]:=t;
t:=A[i];
A[i]:=A[j];
A[j]:=t;
t:=B[i];
B[i]:=B[j];
B[j]:=t;
inc(i);
dec(j);
End;
Until i>j;
Sapxep(L,j);Sapxep(i,H);
End;
Function kt(i,j:integer):boolean;
Var p,l:integer;
Begin
kt:=False;
For p:=A[i]+1 to B[i]-1 do
D[p]:=False;
writeln;
If not(D[A[j]]) or not(D[B[j]]) then begin FillChar(D,SizeOf(D),True); exit; end;
kt:=True;
FillChar(D,SizeOf(D),True);
End;
Procedure Install;
Var i,j,max,kq:integer;
Begin
F[1]:=C[1];
max:=-1;
For k:=2 to n do
Begin
f[k]:= 0;
For j:=k-1 downto 1 do
If b[j] <= a[k] then
begin
f[k]:= f[j] + c[k];
break;
end;
max:=-1;
If F[k]=0 then F[k]:=C[k];
If F[k-1]>=F[k] then F[k]:=F[k-1];
End;
writeln(F[n]);
End;
BEGIN
Init;
Sapxep(1,N);
Install;
readln
END.