Created
December 20, 2014 18:57
-
-
Save ser1zw/7eb1f7ace5d1512666a8 to your computer and use it in GitHub Desktop.
paiza online hackathon vol.1 https://paiza.jp/poh/ec-campaign
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
# 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