Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Educational Codeforces Round 3
n = gets.chomp.to_i
m = gets.chomp.to_i
a = []
n.times do
a << gets.chomp.to_i
end
res = 0
a.sort.reverse.each do |i|
break if m <= 0
m -= i
res += 1
end
puts res
n, m = gets.chomp.split(" ").map(&:to_i)
books = gets.chomp.split(" ").map(&:to_i)
dic = Hash.new(0)
res = 0
books.each do |k|
dic[k] += 1
end
(1..m).to_a.combination(2) do |i, j|
res += dic[i] * dic[j]
end
puts res
# [Editorial of Educational Codeforces Round 3 - Codeforces](http://codeforces.com/blog/entry/22187)
n = gets.chomp.to_i
m = gets.chomp.split(" ").map(&:to_i).sort
msum = m.inject(:+)
mmod = msum % n
if mmod == 0
mm = Array.new(n, msum / n)
else
mm = Array.new(n - mmod, msum / n) + Array.new(mmod, msum / n + 1)
end
res = 0
m.zip(mm).each do |a, b|
res += (a - b).abs
end
puts res / 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment