Codeforces 1090A - Company Merging - [签到水题][2018-2019 Russia Open High School Programming Contest Problem A]
题目链接:https://codeforces.com/contest/1090/problem/A
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.
Input
The first line contains a single integer n — the number of companies in the conglomerate (1≤n≤2⋅10^5). 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⋅10^5). Then mi integers follow: the salaries of the employees. All salaries are positive and do not exceed 10^9.
The total number of employees in all companies does not exceed 2⋅10^5.
Output
Output a single integer — the minimal total increase of all employees that allows to merge all companies.
Example
input
3
2 4 3
2 2 1
3 1 1 1
output
13
Note
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.
题解:
要将 $n$ 家公司合并,每次只能合并两家,而且只有当两家公司的最高薪资相等时才能合并。而且,一旦提薪,是所有员工同时提薪。
因此,至少所有公司的最高薪资都要提到和最高薪资最大的那家公司一样才行。这样一来,很容易就能计算出总高要提薪多少。
AC代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+;
int n;
struct Com{
int ct,mx;
}com[maxn];
int main()
{
scanf("%d",&n);
int _max=;
for(int i=;i<=n;i++)
{
scanf("%d",&com[i].ct);
com[i].mx=;
for(int j=,x;j<=com[i].ct;j++)
{
scanf("%d",&x);
com[i].mx=max(com[i].mx,x);
}
_max=max(_max,com[i].mx);
}
long long ans=;
for(int i=;i<=n;i++)
{
if(com[i].mx<_max)
ans+=(long long)com[i].ct * (_max-com[i].mx);
}
cout<<ans<<endl;
}
Codeforces 1090A - Company Merging - [签到水题][2018-2019 Russia Open High School Programming Contest Problem A]的更多相关文章
- Codeforces 1090M - The Pleasant Walk - [签到水题][2018-2019 Russia Open High School Programming Contest Problem M]
题目链接:https://codeforces.com/contest/1090/problem/M There are n houses along the road where Anya live ...
- Codeforces 1090D - Similar Arrays - [思维题][构造题][2018-2019 Russia Open High School Programming Contest Problem D]
题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of ...
- Codeforces 1090B - LaTeX Expert - [字符串模拟][2018-2019 Russia Open High School Programming Contest Problem B]
题目链接:https://codeforces.com/contest/1090/problem/B Examplesstandard input The most famous characters ...
- Codeforces Gym 100286G Giant Screen 水题
Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...
- codeforces 577B B. Modulo Sum(水题)
题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- codeforces 696A Lorenzo Von Matterhorn 水题
这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...
- CodeForces 589I Lottery (暴力,水题)
题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...
- HDU 6300.Triangle Partition-三角形-水题 (2018 Multi-University Training Contest 1 1003)
6300.Triangle Partition 这个题就是输出组成三角形的点的下标. 因为任意三点不共线,所以任意三点就可以组成三角形,直接排个序然后输出就可以了. 讲道理,没看懂官方题解说的啥... ...
随机推荐
- k8s cronjob设置作业失败后退出不重复执行
Optional parameters backoffLimit: Number of retries for pods launched by the job. If you want your p ...
- Unity应用架构设计(8)——使用ServiceLocator实现对象的注入
对象的 『注入』 是企业级软件开发经常听到的术语.如果你是一个 Java 程序员,一定对注入有着深刻的映像.不管是SSH框架还是SSM框架,Spring 全家桶永远是绕不过去的弯.通过依赖注入,可以有 ...
- C# C/S程序出错:ContextSwitchDeadlock is detected
选择菜单栏[调试]->[窗口]->[异常设置] 使用快捷键Ctrl + Alt + E,可以快速打开该对话框 通过取消勾选或者勾选进行设置即可. https://blog.csdn.net ...
- ubuntu代理设置
很多时候,服务器都没有连接外部互联网的条件,需要利用代理服务器才能够访问外网资源进行软件包的升级: ubuntu修改apt-get的代理可以使用代理进行安装包的升级: ubuntu@ubuntu:~$ ...
- GridView不执行RowCommand事件
web.config里把viewstate禁用了.如果是的话在页面里单独开起来就好了. <%@ Page Title="" Language="C#" M ...
- 【转载】史上最全:TensorFlow 好玩的技术、应用和你不知道的黑科技
[导读]TensorFlow 在 2015 年年底一出现就受到了极大的关注,经过一年多的发展,已经成为了在机器学习.深度学习项目中最受欢迎的框架之一.自发布以来,TensorFlow 不断在完善并增加 ...
- 重读redis设计与实现
重读了一遍redis设计与实现,这次收获也不错,把之前还有些疑惑的点:redis跳跃表的原理.redis持久化的方法.redis复制.redis sentinel.redis集群等,都重新熟悉了一遍, ...
- Groovy 和 Gradle
0.Groovy和Gradle是什么关系? Gradle,自动化构建工具,通过简单编写Groovy脚本,便可进行依赖管理并完成项目构建: 1. Groovy有什么用? 脚本+Java代码: 2. Gr ...
- 微信小程序,图片居中显示,适配不同机型
<view style='width:100%;height:100%;text-align:center;' class="picture-2"> <ima ...
- top-N 抽样
1, 使用hive标记random:(如果是mr,就自己标记random值) use ps; set mapred.job.priority=VERY_HIGH; set mapred.job ...