Create a gist now

Instantly share code, notes, and snippets.

@whatalnk /a.rb
Created Sep 27, 2015

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