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