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/074.pas | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 others/volume1/074.pas (limited to 'others/volume1/074.pas') diff --git a/others/volume1/074.pas b/others/volume1/074.pas new file mode 100644 index 0000000..6006157 --- /dev/null +++ b/others/volume1/074.pas @@ -0,0 +1,30 @@ +var + n, i, j, max: int16; + a: array of int64; + +function zigzag(i, j: int16): boolean; + begin + if j - i < 2 then + exit(true); + if (a[j - 1] - a[j - 2]) * (a[j - 1] - a[j]) > 0 then + exit(true); + zigzag := false + end; + +begin + readln(n); + setlength(a, n); + for i := n - 1 downto 0 do + read(a[i]); + max := 0; + while i < n - 1 do + for j := i + 1 to n - 1 do + if (j = n - 1) or + not zigzag(i, j + 1) then + begin + if j - i > max then + max := j - i; + i := j + end; + writeln(max + 1) +end. -- cgit 1.4.1