Last active
December 30, 2015 03:09
-
-
Save kyuu1999/7767883 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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