Skip to content

Instantly share code, notes, and snippets.

@kyuu1999
Last active December 30, 2015 03:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyuu1999/7767883 to your computer and use it in GitHub Desktop.
Save kyuu1999/7767883 to your computer and use it in GitHub Desktop.
my (@price,@day);
<STDIN> =~ /(\d+) (\d+)/;
$price[$_] = <STDIN> for (0..($1-1));
$day[$_] = <STDIN> for (0..($2-1));
@price = sort {$a <=> $b} @price;
for my $setprice (@day){
my @tmp = grep { $_ <= $setprice - $price[0] } @price;
my $check = 0;
unless ($price[0] < $setprice / 2) {
print "0\n";
next;
}
while (my $first = pop @tmp){
for (@tmp) {
my $same = $first + $_;
last if $same > $setprice;
$check = $same if $check < $same;
}
last if $check == $setprice;
}
print $check . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment