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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 of length and of length , both sorted in non-decreasing order, consider all products (, ).
Sort these products with multiplicity and output the -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 . Line 2 lists values of . Line 3 lists values of .
Output
- Print the -th smallest signed integer product.
Subtasks
- Subtask 1 (20 points): ; ; sorted non-decreasing; .
- Subtask 2 (30 points): ; ; sorted non-decreasing; .
- Subtask 3 (50 points): ; ; sorted non-decreasing; .
Examples
Input
4 2 6
-4 -2 0 3
2 4
Output
0
Explanation
For and , the sorted products are . The sixth one is 0.