use strict; use warnings; use utf8; chomp(my $l = ); chomp(my $n = ); chomp(my $w = ); my @wi = sort {$a <=> $b } split / /,$w; my $ans = 0; for (@wi){ $ans++ if ($l -= $_) >= 0; } print $ans , "\n";