about summary refs log tree commit diff
path: root/others/volume1/069.pas
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-19 11:37:07 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-19 11:37:07 +0700
commita53c4128c29f98b5fdfd9b0e13a3bbe094d975ec (patch)
tree77351187cc721bb535ffb3ff140e1355276ba8c2 /others/volume1/069.pas
parentfed71ad5b9c7e3524931b939ec369a559cf2b0b9 (diff)
downloadcp-a53c4128c29f98b5fdfd9b0e13a3bbe094d975ec.tar.gz
Update others/volume1
Diffstat (limited to 'others/volume1/069.pas')
-rw-r--r--others/volume1/069.pas40
1 files changed, 40 insertions, 0 deletions
diff --git a/others/volume1/069.pas b/others/volume1/069.pas
new file mode 100644
index 0000000..2e92fd8
--- /dev/null
+++ b/others/volume1/069.pas
@@ -0,0 +1,40 @@
+uses clib;
+
+var
+  n, i, j: int16;
+  b, c: array of int64;
+  tmp: uint64 = 18446744073709551615;
+
+function absum(x, y: int64): uint64;
+  begin
+    if (x < 0) and
+       (y < 0) then
+      exit(-x - y)
+    else if (x > 0) and
+            (y > 0) then
+      exit(x + y);
+    absum := abs(x + y)
+  end;
+
+begin
+  readln(n);
+  setlength(b, n);
+  for i := n - 1 downto 0 do
+    read(b[i]);
+  qsort(b);
+  setlength(c, n);
+  for j := 0 to n - 1 do
+    read(c[j]);
+  qsort(c);
+  while (i < n) and
+        (j >= 0) do
+    begin
+      if absum(b[i], c[j]) < tmp then
+        tmp := absum(b[i], c[j]);
+      if b[i] + c[j] < 0 then
+        i := i + 1
+      else
+        j := j - 1
+    end;
+  writeln(tmp)
+end.