题目出处:Codeforces Round #695 (Div. 2)
https
题目描绘
C. Three Bags
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.
Input:
The first line of the input contains three space-separated integers n1, n2 and n3 (1≤n1,n2,n3≤3⋅105, 1≤n1+n2+n3≤3⋅105) — the number of numbers in the three bags.
The i-th of the next three lines contain ni space-separated integers ai,1, ai,2, …, ai,ni (1≤ai,j≤109) — the numbers in the i-th bag.
Output:
Print a single integer — the maximum number which you can achieve in the end.
题目解释
题意:
给三个数组,通过一定的规则对三个数组中的元素进行移动,最后剩下一个数时,对该数进行输出,该数应尽可能最大。
移动规则:
数组A,B,C ,可以选数组A中的a元素,B数组中的b元素,然后对A 数组中的a换成a-b,B数组中的b元素移除。
输出:
利用移动规则使三数组剩下最后一个元素,并使该元素为所有情况中的最大值。
思路
该移动规则意味着对某一元素的移动会使其符合发生改变,又因为A,B,C元素均为正,那么移动数为奇数时该元素为负,为偶数则为正。
也就是说当所有元素移动到最后一个元素身上时,保证损失最少并且增量最多即可。
{ A = { a 1 , a 2 , . . . , a n } B = { b 1 , b 2 , . . . , b n } C = { c 1 , c 2 , . . . , c n } \left\{ \begin{aligned} A=\{a_1,a_2,...,a_n\}\\ B=\{b_1,b_2,...,b_n\}\\ C=\{c_1,c_2,...,c_n\} \end{aligned} \right. ⎩⎪⎨⎪⎧A={ a1,a2,...,an}B={ b1,b2,...,bn}C={ c1,c2,...,c