Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Last active August 6, 2017 02:44
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/057ade35927c51a83a49231d91ece9a5 to your computer and use it in GitHub Desktop.
Save whatalnk/057ade35927c51a83a49231d91ece9a5 to your computer and use it in GitHub Desktop.
ICPC Domestic 2008 Equal Total Scores
# IOJ Domestic 2008
# Equal Total Scores
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1153&lang=jp
while true
n, m = gets.chomp.split(" ").map(&:to_i)
break if n == 0 && m == 0
asum = 0
a = []
n.times do
x = gets.chomp.to_i
asum += x
a << x
end
bsum = 0
b = []
m.times do
x = gets.chomp.to_i
bsum += x
b << x
end
flag = false
cursum = 500
retx = 0
rety = 0
a.each do |x|
y = 2 * x - (asum - bsum)
if !(b.find{|i| 2 * i == y}.nil?) then
flag = true
if (2 * x + y) < cursum then
cursum = 2 * x + y
retx = x
rety = y / 2
end
end
end
if flag then
puts "#{retx} #{rety}"
else
puts -1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment