Problem:
Score: 400 points

Problem Statement

We have N integers A_1, A_2, ..., A_N.

There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list?

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq K \leq \frac{N(N-1)}{2}

-10^9 \leq A_i \leq 10^9\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the answer.

Sample Input 1

4 3
3 3 -4 -2

Sample Output 1

-6

There are six ways to form a pair. The products of those pairs are 9, -12, -6, -12, -6, 8.

Sorting those numbers in ascending order, we have -12, -12, -6, -6, 8, 9. The third number in this list is -6.

Sample Input 2

10 40
5 4 3 2 -1 0 0 0 0 0

Sample Output 2

6

Sample Input 3

30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0

Sample Output 3

448283280358331064

Solution in Perl (v5.18.2) (judge verdict: Time Limit Exceeded)

use strict;
use warnings;

# N K 入力
chomp(my $nk = <>);
my ($n, $k) = split(/ /, $nk);

# A の入力
chomp(my $aaa = <>);
my @a = split(/ /, $aaa);

# A の分類
my @pos_a;
my @neg_a;
my @zero_a;

for (@a){
  if($_>0){
    push @pos_a, $_;
  } elsif ($_<0) {
    push @neg_a, $_;
  } else {
    push @zero_a, $_;
  }
}

# 積の個数
my $pos_a = @pos_a;
my $neg_a = @neg_a;
my $zero_a = @zero_a;

my $pos = $pos_a * ($pos_a-1)/2 + $neg_a * ($neg_a - 1)/2;
my $neg = $pos_a * $neg_a;
my $zero = @zero_a * ($pos_a + $neg_a) + $zero_a * ($zero_a - 1)/2;

# 正、負、0 に分けて積を算出
if ($k <= $neg) {
  my @neg_no;
  for (my $i = 0; $i < $pos_a; $i++){
    for (my $j = 0; $j < $neg_a; $j++){
      push @neg_no, @pos_a[$i] * @neg_a[$j];
    }
  }
  @neg_no = sort {$a <=> $b} @neg_no;
  print @neg_no[$k - 1] . "\n";
} elsif ($k <= $neg+$zero) {
  print "0\n";
} else {
  my @pos_no;
  for (my $i = 0; $i < $pos_a - 1; $i++){
    for (my $j = $i + 1; $j < $pos_a; $j++){
      push @pos_no, @pos_a[$i] * @pos_a[$j];
    }
  }
  for (my $i = 0; $i < $neg_a - 1; $i++){
    for (my $j = $i + 1; $j < $neg_a; $j++){
      push @pos_no, @neg_a[$i] * @neg_a[$j];
    }
  }
  @pos_no = sort {$a <=> $b} @pos_no;
  print @pos_no[$k -1 - $neg - $zero] . "\n";
}