From a53c4128c29f98b5fdfd9b0e13a3bbe094d975ec Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Sun, 19 Feb 2017 11:37:07 +0700 Subject: Update others/volume1 --- others/volume1/069.pas | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 others/volume1/069.pas (limited to 'others/volume1/069.pas') 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. -- cgit 1.4.1