Buying Game You want to buy N N items from a store, which you will visit on Days 1 1, 2…
- User
Buying Game You want to buy N N items from a store, which you will visit on Days 1 1, 2 2, ..., N N. The normal cost of the i i-th item is A i A i .
However, on the i i-th day, there is a promotional event for the i i-th item. On this day, it's cost is B i B i instead. B i B i may be greater, smaller or even equal to A i A i .
Thus, on the i i-th day, the cost of the i i-th item is B i B i while, the j j-th item ( j ≠ i ) (j=i) costs A j A j .
You will buy exactly one item on each of the N N days. All the bought items must be distinct. Find the minimum possible cost.
Input Format The first line of input will contain a single integer T T, denoting the number of test cases. Each test case consists of multiple lines of input. The first line contains N N - the number of items The second line contains A 1 , A 2 , . . . , A N A 1 ,A 2 ,...,A N
- the normal costs of the items The third line contains B 1 , B 2 , . . . . , B N B 1 ,B 2 ,....,B N
- the promotional costs of the items. Output Format For each test case, output on a new line the minimum cost.
Constraints 1 ≤ T ≤ 1 0 4 1≤T≤10 4
1 ≤ N ≤ 2 ⋅ 1 0 5 1≤N≤2⋅10 5
1 ≤ A i , B i ≤ 1 0 9 1≤A i ,B i ≤10 9
The sum of N N over all test cases does not exceed 2 ⋅ 1 0 5 2⋅10 5
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.