PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000190. Tổng cặp phần tử nhỏ thứ K (K-th Sum)
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ổng cặp phần tử nhỏ thứ K (K-th Sum)
K-th Sum
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given two integer arrays and .
For each ordered index pair satisfying , form the sum . There are exactly sums. Different index pairs count separately, even when their sums are equal.
Sort all these sums in nondecreasing order and find the value at position , with positions starting at 1.
Input
- The first line contains integers and .
- The second line contains integers .
- The third line contains integers .
Output
- Print one integer: the -th smallest pair sum, counting duplicates.
Subtasks
- Subtask 1 (20 points): ; for every ; .
- Subtask 2 (30 points): ; for every ; .
- Subtask 3 (50 points): ; for every ; .
Examples
Input
3 5
1 4 6
2 3 5
Output
7
Explanation
For and , the sums by row are:
- From : .
- From : .
- From : .
After sorting all nine sums, we get . Its fifth element is .