CF2229B.Absolute Cinema

入门

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You find yourself with two arrays of positive integers aa and bb, both of length nn. You are to perform the following operation any number of times:

  • select an integer ii (1≤i≤n1 \le i \le n) and swap aia_i and bib_i.

Determine the maximum value of max⁡(a)+∑i=1nbi\max(a) + \sum^{n}_{i = 1}{b_i} attainable if you perform the operations optimally.

你手上有两个长度均为 nn 的正整数数组 aa 和 bb。你可以执行以下操作任意多次:

  • 选择一个整数 ii(1≤i≤n1 \le i \le n),并交换 aia_i 和 bib_i。

若以最优方式执行这些操作,求 max⁡(a)+∑i=1nbi\max(a) + \sum^{n}_{i = 1}{b_i} 的最大可能值。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each testcase contains an integer nn (1≤n≤1051 \le n \le 10^5) — the length of the arrays aa and bb.

The second line of each testcase contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_{n} (1≤ai≤1091 \le a_i \le 10^9).

The third line of each testcase contains nn integers b1,b2,…,bnb_1,b_2,\ldots,b_{n} (1≤bi≤1091 \le b_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)—— 表示数组 aa 和 bb 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_{n}(1≤ai≤1091 \le a_i \le 10^9)。

每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1,b_2,\ldots,b_{n}(1≤bi≤1091 \le b_i \le 10^9)。

保证所有测试用例中 nn 的总和不超过 10510^5。

输出格式

For each testcase, output the maximum value of max⁡(a)+∑i=1nbi\max(a) + \sum^{n}_{i = 1}{b_i} attainable.

对于每个测试用例,输出可达到的 max⁡(a)+∑i=1nbi\max(a) + \sum^{n}_{i = 1}{b_i} 的最大值。

输入输出样例

  • 输入#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\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 11, 33 and 44. So we get:

  • a=[1,3,5,8]a = [1, 3, 5, 8]
  • b=[2,4,6,7]b = [2, 4, 6, 7]

This gives an answer of max⁡([1,3,5,8])+2+4+6+7=8+19=27\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\max([1, 2, 3]) + 4 + 5 + 6 = 3 + 15 = 18,可以证明这是最优解。

测试用例 4:通过交换下标 11、33 和 44 可达到最大值。于是得到:

  • a=[1,3,5,8]a = [1, 3, 5, 8]
  • b=[2,4,6,7]b = [2, 4, 6, 7]

该方案的答案为 max⁡([1,3,5,8])+2+4+6+7=8+19=27\max([1, 3, 5, 8]) + 2 + 4 + 6 + 7 = 8 + 19 = 27,可以证明这是最优解。

输入解题思路,AI测评打分。不知道怎么写?

首页