Skip to content

Instantly share code, notes, and snippets.

@y-yu
Last active December 29, 2015 23:59
Show Gist options
  • Save y-yu/7746863 to your computer and use it in GitHub Desktop.
Save y-yu/7746863 to your computer and use it in GitHub Desktop.
hoge.pl
use strict;
use warnings;
my $l = <STDIN>;
chomp $l;
my ($item_num, $campaign_num) = split / /, $l;
my @items;
for (1..$item_num) {
$l = <STDIN>;
chomp $l;
push @items, $l;
}
my @sum;
for my $i (@items) {
push @sum, ( map { $_ + $i } grep { $i != $_ } @items);
}
for (1..$campaign_num) {
$l = <STDIN>;
chomp $l;
my @r = sort { $b <=> $a } grep { $_ <= $l } @sum;
print ((@r > 0 ? shift @r : 0) . "\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment