about summary refs log tree commit diff
path: root/others/other/game.pas
blob: 5be1da284a0d8265449bcf961bf3f2305891dd2a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
uses
  sortnfind;

var
  f: text;
  n, i, j: smallint;
  b: array of int64;
  c: int64;
  a: qword = 0;


function sign(x: int64): shortint;
  begin
    if x < 0 then
      exit(-1);
    exit(1)
  end;


function min(
  x: qword;
  y, z: int64
): qword;

  var
    tmp: qword;

  begin
    if sign(y) = sign(z) then
      tmp := abs(y) + abs(z)
    else if abs(y) < abs(z) then
      tmp := abs(z) - abs(y)
    else
      tmp := abs(y) - abs(z);

    if tmp < x then
      exit(tmp);
    exit(x)
  end;


begin
  assign(f, 'GAME.INP');
  reset(f);
  readln(f, n);
  setlength(b, n);
  for i := 0 to n - 1 do
    read(f, b[i]);
  qsort(b);
  for i := 0 to n - 1 do
    begin
      read(f, c);
      for j := 0 to n - 1 do
        a := min(a, b[j], c)
    end;
  close(f);

  assign(f, 'GAME.OUT');
  rewrite(f);
  writeln(f, a);
  close(f)
end.