Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created October 15, 2018 12:34
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/2deefc7052d58ffab52ab2919a130fcc to your computer and use it in GitHub Desktop.
Save whatalnk/2deefc7052d58ffab52ab2919a130fcc to your computer and use it in GitHub Desktop.
Code festival 2018 qual B; B
n, x = gets.chomp.split(" ").map(&:to_i)
ab = []
ans = 0
abmax = [0, 0]
n.times do
a, b = gets.chomp.split(" ").map(&:to_i)
ab << [a, b]
ans += a * b
if b > abmax[1]
abmax = [a, b]
elsif b == abmax[1]
if a > abmax[0]
abmax = [a, b]
end
end
end
puts ans - abmax[0] * abmax[1] + (abmax[0] + x) * abmax[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment