Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created April 18, 2019 10:14
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/14d141fc2bee468e6e124cf67f5c2862 to your computer and use it in GitHub Desktop.
Save whatalnk/14d141fc2bee468e6e124cf67f5c2862 to your computer and use it in GitHub Desktop.
AtCoder ABC #116 - C Grand Garden
n = gets.chomp.to_i
h = gets.chomp.split(" ").map(&:to_i)
ans = 0
cnt = 0
while true
n.times do |i|
if h[i] > 0
cnt += 1
h[i] -= 1
else
if cnt != 0
ans += 1
cnt = 0
end
end
end
ans += 1 if cnt != 0
cnt = 0
break if h.all?{|x| x == 0}
end
puts ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment