#/usr/bin/env perl use strict; use warnings; my ($n, $k) = split / /, <>; chomp $k; my %dp; my @vs; for ($_ = 0; $_ < $n; $_++) { my $m = <>; chomp$m; push @vs, $m; } $dp{0} = 1; my $ma = 0; for (my $i = 0; $i < $n; $i++) { for (my $w = 0; $w + $vs[$i] <= $k; $w++) { if (exists$dp{$w}) { $dp{$w + $vs[$i]} = 1; $ma = $w + $vs[$i]; } } } print "$ma\n";