Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
https://paiza.jp/poh/ec-campaign に挑戦したコード
# coding: utf-8
def read_data(count)
c = count.to_i
return if c < 0
ret = []
count.times do
s = gets
next unless s
ret << s.to_i
end
ret
end
def max_price(target, prices)
return if target < 0
return if (prices.nil? || prices.empty?)
return 0 if target <= 0
ps = prices.reject{|pr| pr > target}
return 0 if ps.empty?
max = 0
ps.combination(2).each do |d|
pr = d.first + d.last
next if pr > target
max = pr if pr > max
break if max == target
end
max
end
counts = gets
targets = counts.chomp.split(' ')
pcount = targets.first.to_i
dcount = targets.last.to_i
exit if (pcount < 0 || dcount < 0)
prices = read_data(pcount)
targets = read_data(dcount)
targets.each do |target|
rsl = max_price(target, prices)
puts (rsl ? rsl : 0)
end
exit
@parrot-studio

This comment has been minimized.

Copy link
Owner Author

commented Dec 3, 2013

@parrot-studio

This comment has been minimized.

Copy link
Owner Author

commented Dec 3, 2013

@parrot-studio

This comment has been minimized.

Copy link
Owner Author

commented Dec 3, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.