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: Accepted)

local mfl = math.floor

local n, k = io.read("*n", "*n", "*l")
local t = {}
local str = io.read()
for s in str:gmatch("(-?%d+)") do
  table.insert(t, tonumber(s))
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 mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    local curj = #plus
    for i = 1, #minus do
      local dst = x / minus[i]
      if x % minus[i] ~= 0 then dst = dst + 1 end
      local z = #plus + 1
      for j = curj, 1, -1 do
        if dst <= plus[j] then
          z = j
        else break end
      end
      curj = mmi(#plus, z)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    local r = solve(mid)
    if k <= r 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
    local curj = #minus
    for i = 1, #minus - 1 do
      local dst = x / minus[i]
      local z = curj + 1
      for j = curj, i + 1, -1 do
        if dst < minus[j] then
          z = j
        else
          break
        end
      end
      curj = mmi(#minus, z)
      z = z - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
    end
    right = #plus
    curj = #plus
    for i = 1, #plus - 1 do
      local z = 0
      if plus[i] == 0 then
        if x < 0 then
          z = i
        else
          z = right
        end
      else
        local dst = x / plus[i]
        z = curj + 1
        for j = curj, i + 1, -1 do
          if dst < plus[j] then
            z = j
          else
            break
          end
        end
        curj = mmi(#plus, z)
        z = z - 1
      end
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    local r = solveA(mid)
    if k <= r then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end