#!/usr/bin/perl use strict; use warnings; my ($n, $m) = split / /, <>; my $c = <>; chomp $c; my @array = split / /, $c; @array = sort @array; my $total = 0; for(my $i = 0; $i < $n; $i++) { $total += $array[$i]; if($total == $m) { print $i + 1 . "\n"; last; } elsif($total > $m) { print "$i\n"; last; } } exit;