Codeforces 1090A. Company Merging

合并n个公司,每个公司有若干人,当两个公司的最高薪水相同的时候才能合并,员工的薪水只能增加不能减少,并且要加工资要给所有的人一起加。
问你合并的最小的花费。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL; 
int cnt[202020], n,t,k,ma[202020],num,mm;
LL ans;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i = 0;i<n;i++){
		cin>>k;
		cnt[i] = k;
		int tm = 0;
		while(k--){
			cin>>t;
			tm = max(tm,t);
		}
		ma[i] = tm; 
	}
	for(int i = 0;i<n;i++)mm = max(mm,ma[i]);
	for(int i = 0;i<n;i++){
		ans += (LL)(mm-ma[i])*cnt[i];
	}
	cout<<ans;
	return 0; 
} 

猜你喜欢

转载自blog.csdn.net/winhcc/article/details/85036664