Created
April 18, 2019 10:14
-
-
Save whatalnk/14d141fc2bee468e6e124cf67f5c2862 to your computer and use it in GitHub Desktop.
AtCoder ABC #116 - C Grand Garden
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 | |
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