#C3862. Minimum Power Level

    ID: 47336 Type: Default 1000ms 256MiB

Minimum Power Level

Minimum Power Level

You are given T test cases. For each test case, there are N bottles and M potion types available. Each bottle has an initial power level, and each potion type increases the power of the bottle by a fixed amount.

When a bottle receives a potion treatment, its new power level becomes:

pi=pi+ajp_i' = p_i + a_j

where \(p_i\) is the initial power level of the \(i\)-th bottle and \(a_j\) is the increase provided by the \(j\)-th potion type. Note that each bottle can receive at most one treatment (i.e. you can add at most one potion's increase to that bottle).

Your task is to determine the minimum power level achievable among all bottles after an optimal treatment is applied (i.e. choose a bottle and a potion type such that \(p_i + a_j\) is minimized).

Observation: Since addition is monotonic, the answer for each test case is equal to \(\min(p) + \min(a)\), where \(\min(p)\) represents the minimum initial power and \(\min(a)\) the minimum increase available.

inputFormat

The input is read from standard input (stdin) and has the following format:

T
N M
p1 p2 ... pN
a1 a2 ... aM
... (repeated for each test case)

Where:

  • T is the number of test cases.
  • For each test case:
    • N and M are two integers representing the number of bottles and potion types respectively.
    • The next line contains N integers representing the initial power levels of the bottles.
    • The following line contains M integers representing the increase amounts for each potion type.

outputFormat

For each test case, output a single integer on a new line — the minimum achievable power level after applying a treatment.

## sample
1
3 2
7 8 9
0 2
7