CF2229B.Absolute Cinema
入门
通过率:0%
时间限制:1.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You find yourself with two arrays of positive integers a and b, both of length n. You are to perform the following operation any number of times:
- select an integer i (1≤i≤n) and swap ai and bi.
Determine the maximum value of max(a)+∑i=1nbi attainable if you perform the operations optimally.
你手上有两个长度均为 n 的正整数数组 a 和 b。你可以执行以下操作任意多次:
- 选择一个整数 i(1≤i≤n),并交换 ai 和 bi。
若以最优方式执行这些操作,求 max(a)+∑i=1nbi 的最大可能值。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each testcase contains an integer n (1≤n≤105) — the length of the arrays a and b.
The second line of each testcase contains n integers a1,a2,…,an (1≤ai≤109).
The third line of each testcase contains n integers b1,b2,…,bn (1≤bi≤109).
It is guaranteed that the sum of n over all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤105)—— 表示数组 a 和 b 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)。
每个测试用例的第三行包含 n 个整数 b1,b2,…,bn(1≤bi≤109)。
保证所有测试用例中 n 的总和不超过 105。
输出格式
For each testcase, output the maximum value of max(a)+∑i=1nbi attainable.
对于每个测试用例,输出可达到的 max(a)+∑i=1nbi 的最大值。
输入输出样例
输入#1
4 1 2 1 1 1 2 3 1 2 3 4 5 6 4 2 3 6 7 1 4 5 8
输出#1
3 3 18 27
说明/提示
Test Case 3: No swaps are required, so the answer is max([1,2,3])+4+5+6=3+15=18, it can be proven that this is optimal.
Test Case 4: You can achieve the maximum by swapping indices 1, 3 and 4. So we get:
- a=[1,3,5,8]
- b=[2,4,6,7]
This gives an answer of max([1,3,5,8])+2+4+6+7=8+19=27, it can be proven that this is optimal.
测试用例 3:无需任何交换,因此答案为 max([1,2,3])+4+5+6=3+15=18,可以证明这是最优解。
测试用例 4:通过交换下标 1、3 和 4 可达到最大值。于是得到:
- a=[1,3,5,8]
- b=[2,4,6,7]
该方案的答案为 max([1,3,5,8])+2+4+6+7=8+19=27,可以证明这是最优解。
输入解题思路,AI测评打分。不知道怎么写?