From 7d19f480637e9e880b98dabfbcf8e885b0a2d3b9 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Tue, 21 Feb 2017 21:09:39 +0700 Subject: Update others/volume1 --- others/volume1/077.pas | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 others/volume1/077.pas (limited to 'others/volume1/077.pas') diff --git a/others/volume1/077.pas b/others/volume1/077.pas new file mode 100644 index 0000000..2d13a4d --- /dev/null +++ b/others/volume1/077.pas @@ -0,0 +1,59 @@ +uses clib; + +var + n, m: int32; + a, b, c: array of int64; + i, j: int64; + +begin + readln(n, m); + setlength(a, n); + repeat + dec(n); + read(a[n]) + until n = 0; + qsort(a); + setlength(b, m); + repeat + dec(m); + read(b[m]) + until m = 0; + qsort(b); + + setlength(c, 0); + for i in a do + if (bsearch(b, i) > -1) and + ((length(c) = 0) or (c[length(c) - 1] < i)) then + begin + setlength(c, length(c) + 1); + c[length(c) - 1] := i + end; + + for i in c do + begin + dec(n, 2); + j := bsearch(a, i); + for m := j downto 0 do + if a[m] = i then + inc(n) + else + break; + for m := j to length(a) - 1 do + if a[m] = i then + inc(n) + else + break; + j := bsearch(b, i); + for m := j downto 0 do + if b[m] = i then + inc(n) + else + break; + for m := j to length(b) - 1 do + if b[m] = i then + inc(n) + else + break + end; + writeln(n) +end. -- cgit 1.4.1