Skip to content

Instantly share code, notes, and snippets.

@kou029w
Last active January 10, 2019 09:17
Show Gist options
  • Save kou029w/4905fd94df5032b1ecda9f867b355c6c to your computer and use it in GitHub Desktop.
Save kou029w/4905fd94df5032b1ecda9f867b355c6c to your computer and use it in GitHub Desktop.
@kou029w
Copy link
Author

kou029w commented Oct 12, 2017

整理した

n, c = STDIN.gets.split(' ').map(&:to_i)

sum = 0
l = STDIN.read.split("\n").map(&:to_i).each {|i| sum += (i == c || i + 1 == c ? 1 : 0) }.delete_if {|i| i == c || i + 1 == c }.sort

while i = l.pop
  sum+=1
  l.each_with_index do |j,ix|
    if i + j + 1 <= c
      l.delete_at(ix)
      break
    end
  end
end

puts sum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment