Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created September 27, 2015 03:44
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 whatalnk/2a7f9b8e0d2947429547 to your computer and use it in GitHub Desktop.
Save whatalnk/2a7f9b8e0d2947429547 to your computer and use it in GitHub Desktop.
Code Festival 2015 Qual A
n = gets.chomp
puts n[0..-5] + "2015"
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
s = 0
a.each do |i|
t = s * 2 + i
s = t
end
puts s
n, t = gets.chomp.split(" ").map(&:to_i)
hw = []
a0 = 0
n.times do
a, b = gets.chomp.split(" ").map(&:to_i)
c = a - b
hw << [a, b, c]
a0 += a
end
hw2 = hw.sort {|a, b|
a[2] <=> b[2]
}.reverse
res = 0
while a0 > t
if hw2.empty?
res = -1
break
end
a0 -= hw2.shift[2]
res += 1
end
puts res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment