Created
October 12, 2017 07:22
-
-
Save whatalnk/c515a994cfffbecdd8835d5b03edaa69 to your computer and use it in GitHub Desktop.
AtCoder ARC #036 B - 山のデータ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
arr = [] | |
n.times do | |
arr << gets.chomp.to_i | |
end | |
peaks = [0] | |
(1...(n-1)).each do |i| | |
if arr[i] > arr[i - 1] && arr[i] > arr[i + 1] | |
peaks << i | |
end | |
end | |
peaks << n - 1 | |
ans = 0 | |
peaks.each do |i| | |
# left | |
left = 0 | |
if i != 0 | |
i.downto(1) do |di| | |
if arr[di] > arr[di-1] | |
left += 1 | |
else | |
break | |
end | |
end | |
end | |
# right | |
right = 0 | |
if i != n - 1 | |
i.upto(n-2) do |di| | |
if arr[di] > arr[di+1] | |
right += 1 | |
else | |
break | |
end | |
end | |
end | |
ans = [ans, left + right + 1].max | |
end | |
puts ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment