Kwwiker

Отбор 8.27

Aug 9th, 2020
108
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const
  2.   s = 5;
  3.  
  4. var
  5.   n, t, i, j, min: integer;
  6.   a: array [1..s] of integer;
  7.   ost: array [1..2] of array [0..2] of integer;// 1 - max, 2 - min
  8.  
  9. begin
  10.   min := 1001;
  11.   readln(n);
  12.   for i := 1 to 2 do
  13.     for j := 0 to 2 do
  14.     begin
  15.       if (i = 1) then
  16.         ost[i, j] := 0;
  17.       if (i = 2) then
  18.         ost[i, j] := 1001;
  19.     end;
  20.   for i := 1 to s do
  21.     readln(a[i]);
  22.   for i := s + 1 to n do
  23.   begin
  24.     if (a[1] > ost[1, a[1] mod 3]) then
  25.       ost[1, a[1] mod 3] := a[1];
  26.     if (a[1] < ost[2, a[1] mod 3]) then
  27.       ost[2, a[1] mod 3] := a[1];
  28.     readln(t);
  29.     if (ost[1, t mod 3] <> 0) then begin
  30.       if (ost[1, t mod 3] - t < min) then
  31.         min := ost[1, t mod 3] - t;
  32.       if (t - ost[1, t mod 3] < min) then
  33.         min := t - ost[1, t mod 3];
  34.     end;
  35.     if (ost[2, t mod 3] <> 1001) then begin
  36.       if (ost[2, t mod 3] - t < min) then
  37.         min := ost[2, t mod 3] - t;
  38.       if (t - ost[2, t mod 3] < min) then
  39.         min := t - ost[2, t mod 3];
  40.     end;
  41.     for j := 1 to s - 1 do
  42.       a[j] := a[j + 1];
  43.     a[s] := t;
  44.   end;
  45.   if (min = 1001) then
  46.     writeln('NO')
  47.   else
  48.     writeln(min);
  49. end.
RAW Paste Data