Please, test my program... Whats wrong? Can you give me any tests?
Program p1019;
Const MaxN = 6000;
Var S : Array[1..MaxN, 1..2]of Longint;
Del : Array[1..MaxN]of Byte;
N, s0, ai, bi : Longint;
ci : Char;
Procedure Check;
Var i, j, k : Longint;
begin
k := 0;
for i := 1 to s0 do begin
if i > s0 - k then break;
if (Del[i] = 1) or (S[i, 1] = S[i, 2]) then begin
k := k + 1;
for j := i to s0 - 1 do
S[j] := S[j + 1];
end;
end;
s0 := s0 - k;
end;
Procedure Black;
Var i, ts0 : Longint;
begin
FillChar(Del, SizeOf(Del), 0);
ts0 := s0;
for i := 1 to s0 do
if (ai <= S[i, 1]) and (bi >= S[i, 1]) and (bi <= S[i, 2]) then
S[i, 1] := bi else
if (ai >= S[i, 1]) and (ai <= S[i, 2]) and (bi >= S[i, 2]) then
S[i, 2] := ai else
if (ai <= S[i, 1]) and (bi >= S[i, 2]) then
Del[i] := 1 else
if (ai >= S[i, 1]) and (bi <= S[i, 2]) then begin
ts0 := ts0 + 1;
S[ts0, 1] := bi;
S[ts0, 2] := S[i, 2];
S[i, 2] := ai;
end;
s0 := ts0;
Check;
end;
Procedure Merge;
Var i, j : Longint;
ex : Boolean;
begin
FillChar(Del, SizeOf(Del), 0);
While True do begin
ex := true;
for i := 1 to s0 - 1 do
if Del[i] = 0 then
for j := i + 1 to s0 do
if Del[j] = 0 then
if (S[i, 1] <= S[j, 1]) and (S[i, 2] >= S[j, 1]) then
begin
if S[j, 2] > S[i, 2] then S[i, 2] := S[j, 2];
Del[j] := 1;
ex := false;
end else
if (S[i, 1] <= S[j, 2]) and (S[i, 2] >= S[j, 2]) then
begin
if S[j, 1] <= S[i, 1] then S[i, 1] := S[j, 1];
Del[j] := 1;
ex := false;
end else
if (S[i, 1] >= S[j, 1]) and (S[i, 2] <= S[j, 2]) then
begin
Del[i] := 1;
ex := false;
end else
if (S[j, 1] >= S[i, 1]) and (S[j, 2] <= S[i, 2]) then
begin
Del[j] := 1;
ex := false;
end;
if ex then break;
end;
end;
Procedure WriteIt;
Var L, R, i : Longint;
begin
L := 0; R := 0;
for i := 1 to s0 do
if (S[i, 2] - S[i, 1] > R - L) or
((S[i, 2] - S[i, 1] = R - L) and (S[i, 1] < L)) then begin
L := S[i, 1];
R := S[i, 2];
end;
Writeln(L, ' ', R);
end;
begin
S[1, 1] := 0; S[1, 2] := 1000000000;
s0 := 1;
Readln(N);
While N > 0 do begin
N := N - 1;
Readln(ai, bi, ci, ci);
if ai >= bi then Continue;
if ci = 'b' then
Black
else begin
s0 := s0 + 1;
S[s0, 1] := ai;
S[s0, 2] := bi;
end;
end;
Merge;
WriteIt;
end.