Skip to content

Instantly share code, notes, and snippets.

@yoshiokatsuneo
Created December 8, 2014 08:11
Show Gist options
  • Save yoshiokatsuneo/57ed6981c9e9f316b36f to your computer and use it in GitHub Desktop.
Save yoshiokatsuneo/57ed6981c9e9f316b36f to your computer and use it in GitHub Desktop.
# POH 3 // greedy, bit
@m = gets.to_i
@n = gets.to_i
@companies = []
@n.times{
q, r = gets.split.map(&:to_i)
@companies.push([q, r])
}
mincost = 99999999999
(0..2**@n).each{|i|
engineers = 0
cost = 0
(0...@n).each{|j|
if (i & (1<<j) != 0) then
engineers += @companies[j][0]
cost += @companies[j][1]
end
}
if engineers >= @m
mincost = [mincost, cost].min
end
}
puts mincost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment