A14039 | Three Bags
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $a$ from the first bag and number $b$ from the second bag. Then, you remove $b$ from the second bag and replace $a$ with $a-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.
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.
输入格式
The first line of the input contains three space-separated integers $n_1$ , $n_2$ and $n_3$ ( $1 \le n_1, n_2, n_3 \le 3\cdot10^5$ , $1 \le n_1+n_2+n_3 \le 3\cdot10^5$ ) — the number of numbers in the three bags.
The $i$ -th of the next three lines contain $n_i$ space-separated integers $a_{{i,1}}$ , $a_{{i,2}}$ , ..., $a_{{i,{{n_i}}}}$ ( $1 \le a_{{i,j}} \le 10^9$ ) — the numbers in the $i$ -th bag.
The $i$ -th of the next three lines contain $n_i$ space-separated integers $a_{{i,1}}$ , $a_{{i,2}}$ , ..., $a_{{i,{{n_i}}}}$ ( $1 \le a_{{i,j}} \le 10^9$ ) — the numbers in the $i$ -th bag.
输出格式
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]$
$[-5, 2], [3, 4, 5], [5]$ (Applying an operation to $(1, 6)$ )
$[-10, 2], [3, 4], [5]$ (Applying an operation to $(-5, 5)$ )
$[2], [3, 4], [15]$ (Applying an operation to $(5, -10)$ )
$[-1], [4], [15]$ (Applying an operation to $(2, 3)$ )
$[-5], [], [15]$ (Applying an operation to $(-1, 4)$ )
$[], [], [20]$ (Applying an operation to $(15, -5)$ )
You can verify that you cannot achieve a bigger number. Hence, the answer is $20$ .
$[1, 2], [6, 3, 4, 5], [5]$
$[-5, 2], [3, 4, 5], [5]$ (Applying an operation to $(1, 6)$ )
$[-10, 2], [3, 4], [5]$ (Applying an operation to $(-5, 5)$ )
$[2], [3, 4], [15]$ (Applying an operation to $(5, -10)$ )
$[-1], [4], [15]$ (Applying an operation to $(2, 3)$ )
$[-5], [], [15]$ (Applying an operation to $(-1, 4)$ )
$[], [], [20]$ (Applying an operation to $(15, -5)$ )
You can verify that you cannot achieve a bigger number. Hence, the answer is $20$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted