#abc376e. E - Max × Sum

E - Max × Sum

Score : 475475 points

问题陈述

给定两个长度为 NN 的序列:A=(A1,A2,,AN)A = (A_1, A_2, \dots, A_N)B=(B1,B2,,BN)B = (B_1, B_2, \dots, B_N)
SS{1,2,,N}\lbrace1, 2, \dots, N\rbrace 的一个大小为 KK 的子集。在这里,找到以下表达式的最小可能值:

$\displaystyle \left(\max_{i \in S} A_i\right) \times \left(\sum_{i \in S} B_i\right).$

你给出了 TT 个测试用例;解决每一个。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given sequences of length NN: A=(A1,A2,,AN)A = (A_1, A_2, \dots, A_N) and B=(B1,B2,,BN)B = (B_1, B_2, \dots, B_N).
Let SS be a subset of {1,2,,N}\lbrace1, 2, \dots, N\rbrace of size KK. Here, find the minimum possible value of the following expression:

$\displaystyle \left(\max_{i \in S} A_i\right) \times \left(\sum_{i \in S} B_i\right).$

You are given TT test cases; solve each of them.

Constraints

  • 1T2×1051 \leq T \leq 2 \times 10^5
  • 1KN2×1051 \leq K \leq N \leq 2 \times 10^5
  • 1Ai,Bi1061 \leq A_i, B_i \leq 10^6
  • The sum of NN over all test cases is at most 2×1052 \times 10^5.
  • All input values are integers.

Input

The input is given from Standard Input in the following format. Here, casei\mathrm{case}_i denotes the ii-th test case.

TT

case1\mathrm{case}_1

case2\mathrm{case}_2

\vdots

caseT\mathrm{case}_T

Each test case is given in the following format:

NN KK

A1A_1 A2A_2 \dots ANA_N

B1B_1 B2B_2 \dots BNB_N

Output

Print TT lines. The ii-th line should contain the answer for the ii-th test case.

Sample Input 1

3
3 2
3 7 6
9 2 4
5 3
6 4 1 5 9
8 6 5 1 7
10 6
61 95 61 57 69 49 46 47 14 43
39 79 48 92 90 76 30 16 30 94

Sample Output 1

42
60
14579

In the first test case, for S={2,3}S = \{2, 3\}, the value of the expression is 7×(2+4)=427 \times (2 + 4) = 42, which is the minimum.