Skip to content

Instantly share code, notes, and snippets.

@fukayatsu
Last active December 30, 2015 00:39
Show Gist options
  • Save fukayatsu/7750737 to your computer and use it in GitHub Desktop.
Save fukayatsu/7750737 to your computer and use it in GitHub Desktop.
# ruby-1.9.3
item_count, campaign_count = gets.chomp.split(' ').map(&:to_i)
items = item_count.times.map { gets.chomp.to_i }
campaigns = campaign_count.times.map { gets.chomp.to_i }
sums = []
items.each.with_index do |item_a, i|
items[0...i].each do |item_b|
sums << (item_a + item_b)
end
end
sums = sums.sort.reverse
campaigns.each do |campaign|
puts (sums.find { |sum| sum <= campaign } || 0)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment