PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000059. Tích nhỏ thứ K của các cặp (Pairs)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tích nhỏ thứ K của các cặp (Pairs)
Pairs
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given integers . For every pair of indices , compute the product . There are exactly products, and equal products are retained with their multiplicities.
Sort all products in nondecreasing order. Find the value at 1-based position in this sorted list. Input elements may be negative, zero, or positive.
Input
- The first line contains integers : the number of elements and desired 1-based rank.
- The second line contains exactly integers .
Output
Print one integer: the -th smallest product over all distinct-index pairs.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Input
4 3
3 3 -4 -2
Output
-6
Explanation
For , the six index-pair products are . Sorting yields . The -rd value is . Equal products appear as many times as their index pairs.