-
-
Save whatalnk/2a7f9b8e0d2947429547 to your computer and use it in GitHub Desktop.
Code Festival 2015 Qual A
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
n = gets.chomp | |
puts n[0..-5] + "2015" |
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
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 |
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
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