(* Simple O(n^3) algorithm for maximum layers *) program Layers(input, output); label 99; const x = 1; y = 2; var S: array [1..200, 1..2] of integer; mark: array [1..200] of boolean; Layer: array [1..200] of integer; n, i, j, k : integer; temp : integer; alive : integer; next : integer; begin n := 0; while (not eof(input)) do begin n := n + 1; readln(S[n,x], S[n,y]); end; (* Bubble sort Points by x-coordinate first *) for i := n downto 2 do begin for j := 1 to i-1 do begin if ((S[j,x] > S[j+1,x]) or ((S[j,x] = S[j+1,x]) and (S[j,y] > S[j+1,y]))) then begin temp := S[j+1,x]; S[j+1,x] := S[j,x]; S[j,x] := temp; temp := S[j+1,y]; S[j+1,y] := S[j,y]; S[j,y] := temp; end; end; end; (* initially everyone is alive *) alive := n; for i := 1 to n do mark[i] := false; (* find the k-th layer as long as some point is alive *) k := 0; while (alive >= 1) do begin k := k + 1; next := 0; for i := 1 to n do if (not mark[i]) then begin for j := i+1 to n do if (not mark[j]) then begin if ((S[i,x] <= S[j,x]) and (S[i,y] <= S[j,y])) then goto 99; end; (* S[i] is maximal among unmarked points *) next := next + 1; Layer[next] := i; mark[i] := true; alive := alive - 1; 99: end; write(k:2, ':'); for i := 1 to next do begin write(' (', S[Layer[i],x]:2, ',', S[Layer[i],y]:2, ')'); end; writeln; end; end. 