Created
September 17, 2018 14:33
-
-
Save whatalnk/5f5e59726d339df95485efa53145fcfd to your computer and use it in GitHub Desktop.
AtCoder AGC #027 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
# 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