sub lower_bound1 { my @sorted; for my $idx ($start..$stop) { my $x=0; my @order = sort { $a->[1] <=> $b->[1] } map { [$x++,$_] } @{ $data[$idx] }; push @sorted,\@order; } #pp \@sorted; my $min=0; for my $idx ($start..$stop) { my $shortest1=$sorted[$idx][1][1]; # 1. shortest my $shortest2=$sorted[$idx][2][1]; # 2. shortest $min+=$shortest1; unless ($idx==$start or $idx == $stop) { $min+=$shortest2; } #pp $min,$shortest1,$shortest2, $sorted[$idx]; } return $min/2; }