CF1467C.Three Bags

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given three bags. Each bag contains a non-empty multiset of numbers. You can perform a number of operations on these bags. In one operation, you can choose any two non-empty bags, and choose one number from each of the bags. Let's say that you choose number aa from the first bag and number bb from the second bag. Then, you remove bb from the second bag and replace aa with a−ba-b in the first bag. Note that if there are multiple occurrences of these numbers, then you shall only remove/replace exactly one occurrence.

You have to perform these operations in such a way that you have exactly one number remaining in exactly one of the bags (the other two bags being empty). It can be shown that you can always apply these operations to receive such a configuration in the end. Among all these configurations, find the one which has the maximum number left in the end.

你有三个袋子。每个袋子中都包含一个非空的数字多重集。你可以对这些袋子执行若干次操作。每次操作中,你可以任选两个非空袋子,并分别从这两个袋子中各选一个数。假设你从第一个袋子中选出数字 aa,从第二个袋子中选出数字 bb,那么你将从第二个袋子中移除 bb,并将第一个袋子中的 aa 替换为 a−ba-b。注意:若某数字在袋子中出现多次,则每次操作仅移除或替换其中恰好一个出现。

你需要执行这些操作,使得最终恰好有一个袋子中剩余一个数,其余两个袋子均为空。可以证明:总能通过若干次操作达到这样的终态。在所有可能的终态中,找出剩余数字最大的那个终态。

输入格式

The first line of the input contains three space-separated integers n1n_1, n2n_2 and n3n_3 (1≤n1,n2,n3≤3⋅1051 \le n_1, n_2, n_3 \le 3\cdot10^5, 1≤n1+n2+n3≤3⋅1051 \le n_1+n_2+n_3 \le 3\cdot10^5) — the number of numbers in the three bags.

The ii-th of the next three lines contain nin_i space-separated integers ai,1a_{{i,1}}, ai,2a_{{i,2}}, ..., ai,nia_{{i,{{n_i}}}} (1≤ai,j≤1091 \le a_{{i,j}} \le 10^9) — the numbers in the ii-th bag.

输入的第一行包含三个用空格分隔的整数 n1n_1、n2n_2 和 n3n_3(1≤n1,n2,n3≤3⋅1051 \le n_1, n_2, n_3 \le 3\cdot10^5,1≤n1+n2+n3≤3⋅1051 \le n_1+n_2+n_3 \le 3\cdot10^5)—— 分别表示三个袋子中数字的个数。

接下来三行中的第 ii 行包含 nin_i 个用空格分隔的整数 ai,1a_{{i,1}}、ai,2a_{{i,2}}、...、ai,nia_{{i,{{n_i}}}}(1≤ai,j≤1091 \le a_{{i,j}} \le 10^9)—— 表示第 ii 个袋子中的数字。

输出格式

Print a single integer — the maximum number which you can achieve in the end.

输出一个整数——最终能够达到的最大数值。

输入输出样例

  • 输入#1

    2 4 1
    1 2
    6 3 4 5
    5

    输出#1

    20
  • 输入#2

    3 2 2
    7 5 4
    2 9
    7 1

    输出#2

    29

说明/提示

In the first example input, let us perform the following operations:

[1,2],[6,3,4,5],[5][1, 2], [6, 3, 4, 5], [5]

[−5,2],[3,4,5],[5][-5, 2], [3, 4, 5], [5] (Applying an operation to (1,6)(1, 6))

[−10,2],[3,4],[5][-10, 2], [3, 4], [5] (Applying an operation to (−5,5)(-5, 5))

[2],[3,4],[15][2], [3, 4], [15] (Applying an operation to (5,−10)(5, -10))

[−1],[4],[15][-1], [4], [15] (Applying an operation to (2,3)(2, 3))

[−5],[],[15][-5], [], [15] (Applying an operation to (−1,4)(-1, 4))

[],[],[20][], [], [20] (Applying an operation to (15,−5)(15, -5))

You can verify that you cannot achieve a bigger number. Hence, the answer is 2020.

在第一个样例输入中,我们执行以下操作:

[1,2],[6,3,4,5],[5][1, 2], [6, 3, 4, 5], [5]

[−5,2],[3,4,5],[5][-5, 2], [3, 4, 5], [5](对 (1,6)(1, 6) 执行一次操作)

[−10,2],[3,4],[5][-10, 2], [3, 4], [5](对 (−5,5)(-5, 5) 执行一次操作)

[2],[3,4],[15][2], [3, 4], [15](对 (5,−10)(5, -10) 执行一次操作)

[−1],[4],[15][-1], [4], [15](对 (2,3)(2, 3) 执行一次操作)

[−5],[],[15][-5], [], [15](对 (−1,4)(-1, 4) 执行一次操作)

[],[],[20][], [], [20](对 (15,−5)(15, -5) 执行一次操作)

你可以验证无法得到更大的数。因此,答案为 2020。

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

首页