Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created December 22, 2015 09:59
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/cfb80ff9a936a2c63f41 to your computer and use it in GitHub Desktop.
Save whatalnk/cfb80ff9a936a2c63f41 to your computer and use it in GitHub Desktop.
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