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 LuaJIT (2.0.4) (judge verdict: Wrong Answer)

local mfl = math.floor

local function comp(a, b)
  return a < b
end

local function lower_bound(ary, x, mul)
  local num = #ary
  if num == 0 then return 1 end
  if not comp(ary[1] * mul, x) then return 1 end
  if comp(ary[num] * mul, x) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if comp(ary[mid] * mul, x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound(ary, left, right, x, mul)
  local num = #ary
  if num == 0 then return 1 end
  if comp(x, ary[left] * mul) then return left end
  if not comp(x, ary[right] * mul) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not comp(x, ary[mid] * mul) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = 0LL + io.read("*n")
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local function solve(x)
    x = -x
    local cnt = 0
    for i = 1, #minus do
      local z = lower_bound(plus, x, minus[i])
      cnt = cnt + (#plus + 1 - z)
      if #plus + 1 - z == 0 then break end
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    for i = 1, #minus - 1 do
      local z = upper_bound(minus, i + 1, right, x, minus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = upper_bound(plus, i + 1, right, x, plus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return k <= cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solveA(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end