Created
May 14, 2016 15:33
-
-
Save whatalnk/1c317f611374f5b7384350f85e65d134 to your computer and use it in GitHub Desktop.
AtCoder ARC #053
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
h, w = gets.chomp.split(" ").map(&:to_i) | |
puts (h - 1) * w + h * (w - 1) |
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
s = gets.chomp | |
d = Hash.new(0) | |
s.split("").each do |c| | |
d[c] += 1 | |
end | |
nodd = 0 | |
chars = 0 | |
d.each do |k, v| | |
if v.odd? | |
nodd += 1 | |
end | |
chars += v / 2 | |
end | |
if nodd == 0 then | |
puts s.length | |
else | |
puts chars / nodd * 2 + 1 | |
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 | |
dec = [] | |
inc = [] | |
while line = gets | |
a, b = line.chomp.split(" ").map(&:to_i) | |
if a < b then | |
dec << [a, b] | |
else | |
inc << [a, b] | |
end | |
end | |
dec.sort_by!{|v| v[0]} | |
inc.sort_by!{|v| -v[1]} | |
ans = 0 | |
curr = 0 | |
dec.each do |x| | |
up, down = x | |
ans = [ans, curr+up].max | |
curr += (up - down) | |
end | |
inc.each do |x| | |
up, down = x | |
ans = [ans, curr+up].max | |
curr += (up - down) | |
end | |
puts ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment