Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
AtCoder ABC 031
a, d = gets.chomp.split(" ").map(&:to_i)
if a == d then
puts a * (a + 1)
elsif a < d then
puts (a + 1) * d
else
puts a * (d + 1)
end
l, h = gets.chomp.split(" ").map(&:to_i)
n = gets.chomp.to_i
n.times do
a = gets.chomp.to_i
if a >= l && a <= h then
puts 0
elsif a < l then
puts l - a
else
puts -1
end
end
n = gets.chomp.to_i
ary = gets.chomp.split(" ").map(&:to_i)
select_aok = ->(tkhs) {
seq_game = Hash.new(0)
n.times do |i|
next if i == tkhs
left = [i, tkhs].min
right = [i, tkhs].max
p_aok = 0
p_tkhs = 0
ary[left..right].each_slice(2) do |a1, a2|
p_tkhs += a1.to_i
p_aok += a2.to_i
end
seq_game[p_aok] = p_tkhs unless seq_game.has_key?(p_aok)
end
p_aok_max = seq_game.keys.max
return seq_game[p_aok_max]
}
points = Array.new()
n.times do |j|
points << select_aok.call(j)
end
puts points.max
Owner

whatalnk commented Nov 24, 2015

  • A
  • B
  • C
  • D
Owner

whatalnk commented Nov 24, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment