Codeforces Round #695 (Div. 2) C. Three Bags

博客介绍了Codeforces Round #695 (Div. 2) C题目的解决方案,涉及如何通过特定的移动规则使得三个数集中只剩下一个数,且这个数是所有可能性中的最大值。移动规则包括从两个非空数集中各取一个数,然后将一个数替换为两数之差。博客讨论了如何找到最佳配置以最大化最后剩下的数,涉及到对数列的操作和策略分析。
摘要由CSDN通过智能技术生成

题目出处: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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值