Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created October 12, 2017 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/c515a994cfffbecdd8835d5b03edaa69 to your computer and use it in GitHub Desktop.
Save whatalnk/c515a994cfffbecdd8835d5b03edaa69 to your computer and use it in GitHub Desktop.
AtCoder ARC #036 B - 山のデータ
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