# use strict; # use warnings; chomp(my $L = <>); <>; chomp(my $W = <>); my @WS = split(/\s/, $W); my $c = 0; my $w = 0; foreach (sort({$a <=> $b} + @WS)) { $w += $_; last if $w > $L; $c++; } print($c, "\n");