about summary refs log tree commit diff
path: root/others/other/game.pas
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-10 21:30:06 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-10 21:35:08 +0700
commit7c9b47ab9149d292d5493c865dfb8742a7450472 (patch)
treec2b8d9759740b02b9dc157b84f32c2860369bf3b /others/other/game.pas
parentf4f486fb4b37b72ca345f95881e44043c728b2c3 (diff)
downloadcp-7c9b47ab9149d292d5493c865dfb8742a7450472.tar.gz
others/other: Add {bin,game}.pas and move others/dict here
Diffstat (limited to 'others/other/game.pas')
-rw-r--r--others/other/game.pas62
1 files changed, 62 insertions, 0 deletions
diff --git a/others/other/game.pas b/others/other/game.pas
new file mode 100644
index 0000000..5be1da2
--- /dev/null
+++ b/others/other/game.pas
@@ -0,0 +1,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.