Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created May 14, 2016 15:33
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/1c317f611374f5b7384350f85e65d134 to your computer and use it in GitHub Desktop.
Save whatalnk/1c317f611374f5b7384350f85e65d134 to your computer and use it in GitHub Desktop.
AtCoder ARC #053
h, w = gets.chomp.split(" ").map(&:to_i)
puts (h - 1) * w + h * (w - 1)
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
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