Skip to content

Instantly share code, notes, and snippets.

@yaasita
Last active December 30, 2015 00:59
Show Gist options
  • Save yaasita/7752851 to your computer and use it in GitHub Desktop.
Save yaasita/7752851 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
my (@item,@campaign);
{
my @head = split(/\s/,<STDIN>);
for (1..$head[0]){
$_=<STDIN>;
push(@item,$_);
}
for (1..$head[1]){
$_=<STDIN>;
push(@campaign,$_);
}
}
my @combination;
for my $i (0..$#item){
push(@combination,$item[$i]+$item[$_]) for $i+1..$#item;
}
{
my %count;
@combination = sort {$a <=> $b} grep {!$count{$_}++} @combination;
}
for my $price (@campaign){
my $out=0;
for(@combination){
last if $_ > $price;
$out=$_;
}
print "$out\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment