Skip to content

Instantly share code, notes, and snippets.

@ser1zw
Created December 20, 2014 18:57
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 ser1zw/7eb1f7ace5d1512666a8 to your computer and use it in GitHub Desktop.
Save ser1zw/7eb1f7ace5d1512666a8 to your computer and use it in GitHub Desktop.
paiza online hackathon vol.1 https://paiza.jp/poh/ec-campaign
# http://paiza.jp/poh/ec-campaign/result/56d00e8d56e2c7b998e1f766a04e9acf
data = $stdin.read.split(/\s/).map(&:to_i)
num_items, campaign_days = data.shift, data.shift
item_prices, target_prices = data.shift(num_items).sort!, data
target_prices.each { |target_price|
h = 0
l = num_items - 1
nearest_price = 0
while h < l
s = item_prices[h] + item_prices[l]
if target_price < s
l -= 1
else
nearest_price = s if nearest_price < s
h += 1
end
end
puts nearest_price
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment