Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const
- s = 5;
- var
- n, t, i, j, min: integer;
- a: array [1..s] of integer;
- ost: array [1..2] of array [0..2] of integer;// 1 - max, 2 - min
- begin
- min := 1001;
- readln(n);
- for i := 1 to 2 do
- for j := 0 to 2 do
- begin
- if (i = 1) then
- ost[i, j] := 0;
- if (i = 2) then
- ost[i, j] := 1001;
- end;
- for i := 1 to s do
- readln(a[i]);
- for i := s + 1 to n do
- begin
- if (a[1] > ost[1, a[1] mod 3]) then
- ost[1, a[1] mod 3] := a[1];
- if (a[1] < ost[2, a[1] mod 3]) then
- ost[2, a[1] mod 3] := a[1];
- readln(t);
- if (ost[1, t mod 3] <> 0) then begin
- if (ost[1, t mod 3] - t < min) then
- min := ost[1, t mod 3] - t;
- if (t - ost[1, t mod 3] < min) then
- min := t - ost[1, t mod 3];
- end;
- if (ost[2, t mod 3] <> 1001) then begin
- if (ost[2, t mod 3] - t < min) then
- min := ost[2, t mod 3] - t;
- if (t - ost[2, t mod 3] < min) then
- min := t - ost[2, t mod 3];
- end;
- for j := 1 to s - 1 do
- a[j] := a[j + 1];
- a[s] := t;
- end;
- writeln(min);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement