Last active
April 29, 2017 08:57
-
-
Save whatalnk/5bdb00adacb65e53cdcc353bc72d7073 to your computer and use it in GitHub Desktop.
AtCoder ABC #059
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
puts gets.chomp.split(" ").map{|s| s[0].upcase}.join("") |
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
a = gets.chomp.to_i | |
b = gets.chomp.to_i | |
if a > b then | |
puts "GREATER" | |
elsif a < b then | |
puts "LESS" | |
else | |
puts "EQUAL" | |
end |
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 | |
a = gets.chomp.split(" ").map(&:to_i) | |
# +-+- | |
ret1 = 0 | |
sum = 0 | |
n.times do |i| | |
sum += a[i] | |
if i.even? && sum <= 0 then | |
ret1 += (sum.abs + 1) | |
sum = 1 | |
elsif i.odd? && sum >= 0 then | |
ret1 += (sum.abs + 1) | |
sum = -1 | |
end | |
end | |
#-+-+ | |
ret2 = 0 | |
sum = 0 | |
n.times do |i| | |
sum += a[i] | |
if i.even? && sum >= 0 then | |
ret2 += (sum.abs + 1) | |
sum = -1 | |
elsif i.odd? && sum <= 0 then | |
ret2 += (sum.abs + 1) | |
sum = 1 | |
end | |
end | |
puts [ret1, ret2].min |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment