Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created September 17, 2018 14:33
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/5f5e59726d339df95485efa53145fcfd to your computer and use it in GitHub Desktop.
Save whatalnk/5f5e59726d339df95485efa53145fcfd to your computer and use it in GitHub Desktop.
AtCoder AGC #027 A
# AGC027 A
n, x = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i).sort
s = a.inject(:+)
if s == x
puts n
elsif s < x
puts n - 1
else
ss = 0
n.times do |i|
ss += a[i]
if ss > x
puts i
exit
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment