CF1090A.Company Merging
普及-
通过率:0%
时间限制:1.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A conglomerate consists of n companies. To make managing easier, their owners have decided to merge all companies into one. By law, it is only possible to merge two companies, so the owners plan to select two companies, merge them into one, and continue doing so until there is only one company left.
But anti-monopoly service forbids to merge companies if they suspect unfriendly absorption. The criterion they use is the difference in maximum salaries between two companies. Merging is allowed only if the maximum salaries are equal.
To fulfill the anti-monopoly requirements, the owners can change salaries in their companies before merging. But the labor union insists on two conditions: it is only allowed to increase salaries, moreover all the employees in one company must get the same increase.
Sure enough, the owners want to minimize the total increase of all salaries in all companies. Help them find the minimal possible increase that will allow them to merge companies into one.
一家集团由 n 家公司组成。为便于管理,各公司所有者决定将所有公司合并为一家。根据法律规定,每次仅允许合并两家公司,因此所有者计划每次选出两家公司,将其合并为一家,并持续此过程,直至只剩一家公司。
但反垄断部门禁止合并被怀疑存在“非友好并购”的公司。其判定标准是:两家公司各自的最高薪资之差。仅当两家公司的最高薪资相等时,才允许合并。
为满足反垄断要求,所有者可在合并前调整各自公司员工的薪资。但工会坚持两项条件:
- 仅允许提高薪资(不允许降低);
- 同一公司内所有员工的薪资增幅必须相同。
当然,所有者希望最小化所有公司中所有员工薪资增加的总和。请帮助他们找出实现最终合并为一家公司所需的最小总薪资增幅。
输入格式
The first line contains a single integer n — the number of companies in the conglomerate (1≤n≤2⋅105). Each of the next n lines describes a company.
A company description start with an integer mi — the number of its employees (1≤mi≤2⋅105). Then mi integers follow: the salaries of the employees. All salaries are positive and do not exceed 109.
The total number of employees in all companies does not exceed 2⋅105.
第一行包含一个整数 n —— 集团中公司的数量(1≤n≤2⋅105)。接下来的 n 行每行描述一家公司。
每家公司的描述以一个整数 mi 开始 —— 该公司员工的数量(1≤mi≤2⋅105)。随后是 mi 个整数:员工的薪资。所有薪资均为正数,且不超过 109。
所有公司员工总数不超过 2⋅105。
输出格式
Output a single integer — the minimal total increase of all employees that allows to merge all companies.
输出一个整数——使所有公司能够合并的全体员工薪资总增幅的最小值。
输入输出样例
输入#1
3 2 4 3 2 2 1 3 1 1 1
输出#1
13
说明/提示
One of the optimal merging strategies is the following. First increase all salaries in the second company by 2, and merge the first and the second companies. Now the conglomerate consists of two companies with salaries [4,3,4,3] and [1,1,1]. To merge them, increase the salaries in the second of those by 3. The total increase is 2+2+3+3+3=13.
一种最优的合并策略如下:首先将第二家公司的所有工资增加 2,然后将第一家和第二家公司合并。此时联合体包含两家公司,其工资分别为 [4,3,4,3] 和 [1,1,1]。为合并这两家公司,需将其中第二家公司的工资增加 3。总增加量为 2+2+3+3+3=13。
输入解题思路,AI测评打分。不知道怎么写?