#P10417. [蓝桥杯 2023 国 A] 第 K 小的和

[蓝桥杯 2023 国 A] 第 K 小的和

Problem Description

Given two sequences AA and BB, with lengths nn and mm, respectively.

Define another sequence CC that contains all pairwise sums of numbers from AA and BB (CC has a total of n×mn\times m numbers). Ask what the KK-th smallest number in CC is. Note that duplicate values must be counted multiple times. For example, in 1,1,2,31,1,2,3, both the smallest and the second smallest are 11, and 33 is the 44-th smallest.

Input Format

The first line contains three integers n,m,Kn,m,K, separated by one space between adjacent integers.

The second line contains nn integers, representing A1,A2,,AnA_1,A_2,\ldots,A_n, separated by one space between adjacent integers.

The third line contains mm integers, representing B1,B2,,BmB_1,B_2,\ldots,B_m, separated by one space between adjacent integers.

Output Format

Output one line containing one integer, which is the answer.

3 4 5
1 3 4
2 3 5 6

6

Hint

【Constraints and Conventions for Testcases】

  • For 40%40\% of the testcases, n,m5000n,m\le 5000, Ai,Bi1000A_i,B_i\le 1000.
  • For all testcases, 1n,m1051\le n,m\le 10^5, 1Ai,Bi1091\le A_i,B_i\le 10^9, 1Kn×m1\le K\le n\times m.

Translated by ChatGPT 5