PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000198. Tích nhỏ thứ K giữa hai dãy đã sắp xếp (Kth Smallest Product of Two Sorted Arrays)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tích nhỏ thứ K giữa hai dãy đã sắp xếp (Kth Smallest Product of Two Sorted Arrays)

Kth Smallest Product of Two Sorted Arrays

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given two integer arrays AA of length nn and BB of length mm, both sorted in non-decreasing order, consider all nmnm products AiBjA_iB_j (1≤i≤n1\le i\le n, 1≤j≤m1\le j\le m).

Sort these products with multiplicity and output the kk-th smallest (1-based). Values may be negative, zero, or positive. Distinct index pairs are counted separately even if their products coincide.

Input

  • Line 1 contains n,m,kn,m,k. Line 2 lists nn values of AA. Line 3 lists mm values of BB.

Output

  • Print the kk-th smallest signed integer product.

Subtasks

  • Subtask 1 (20 points): 1≤n,m≤301\le n,m\le30; −20≤Ai,Bj≤20-20\le A_i,B_j\le20; sorted non-decreasing; 1≤k≤nm1\le k\le nm.
  • Subtask 2 (30 points): 1≤n,m≤15001\le n,m\le1500; −1000≤Ai,Bj≤1000-1000\le A_i,B_j\le1000; sorted non-decreasing; 1≤k≤nm1\le k\le nm.
  • Subtask 3 (50 points): 1≤n,m≤500001\le n,m\le50000; −105≤Ai,Bj≤105-10^5\le A_i,B_j\le10^5; sorted non-decreasing; 1≤k≤nm1\le k\le nm.

Examples

Input

4 2 6
-4 -2 0 3
2 4

Output

0

Explanation

For A=[−4,−2,0,3]A=[-4,-2,0,3] and B=[2,4]B=[2,4], the sorted products are [−16,−8,−8,−4,0,0,6,12][-16,-8,-8,-4,0,0,6,12]. The sixth one is 0.