Last active
November 24, 2015 04:14
-
-
Save whatalnk/ed28dbcb82fc4475ea0b to your computer and use it in GitHub Desktop.
AtCoder ABC 031
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, 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 |
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
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 |
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 | |
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 |
- A
- B
- C
- D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Welcome to AtCoder Beginner Contest 031 - AtCoder Beginner Contest 031 | AtCoder