只做了两个就去上课去啦...
A. Company Merging
time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard output

A conglomerate consists of nn 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 nn — the number of companies in the conglomerate (1≤n≤2⋅1051≤n≤2⋅105). Each of the next nn lines describes a company.

A company description start with an integer mimi — the number of its employees (1≤mi≤2⋅1051≤mi≤2⋅105). Then mimi integers follow: the salaries of the employees. All salaries are positive and do not exceed 109109.

The total number of employees in all companies does not exceed 2⋅1052⋅105.

Output

Output a single integer — the minimal total increase of all employees that allows to merge all companies.

Example
input

Copy
3
2 4 3
2 2 1
3 1 1 1
output

Copy
13
Note

One of the optimal merging strategies is the following. First increase all salaries in the second company by 22, and merge the first and the second companies. Now the conglomerate consists of two companies with salaries [4,3,4,3][4,3,4,3] and [1,1,1][1,1,1]. To merge them, increase the salaries in the second of those by 33. The total increase is 2+2+3+3+3=132+2+3+3+3=13.

思路:一个大集团下面有n个公司,每个公司m个员工,每个员工的工资mi,现在要合并公司.两两合并,最后只剩一个才行,合并要求是,两个公司之间的员工最大工资相等才行.

只要记录每个公司的最大工资,然后排序,再开始从小到大挨着两两合并.

#include <iostream>
#include <algorithm>
#include <cstdlib> using namespace std; struct everycom{
int maxx;
int num;
}; struct everycom ec[]; int cmp(struct everycom a,struct everycom b){
return a.maxx<b.maxx;
} int main(){
int n,m;
int now=;
int maxx=;
//while(scanf("%d",&n)){
scanf("%d",&n);
long long sum=;
long long nownum=;
for(int i=;i<n;i++){
cin>>m;
ec[i].num=m;
maxx=;
for(int j=;j<m;j++){
cin>>now;
maxx=now>maxx?now:maxx;
}
ec[i].maxx=maxx;
}
sort(ec,ec+n,cmp);
for(int i=;i<n-;i++){
long long tmp=ec[i+].maxx-ec[i].maxx;
nownum+=ec[i].num;
sum+=tmp*nownum;
}
cout<<sum<<endl;
}

M. The Pleasant Walk

time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard output

There are nn houses along the road where Anya lives, each one is painted in one of kk possible colors.

Anya likes walking along this road, but she doesn't like when two adjacent houses at the road have the same color. She wants to select a long segment of the road such that no two adjacent houses have the same color.

Help Anya find the longest segment with this property.

Input

The first line contains two integers nn and kk — the number of houses and the number of colors (1≤n≤1000001≤n≤100000, 1≤k≤1000001≤k≤100000).

The next line contains nn integers a1,a2,…,ana1,a2,…,an — the colors of the houses along the road (1≤ai≤k1≤ai≤k).

Output

Output a single integer — the maximum number of houses on the road segment having no two adjacent houses of the same color.

Example
input

Copy
8 3
1 2 3 3 2 1 2 2
output

Copy
4
Note

In the example, the longest segment without neighboring houses of the same color is from the house 4 to the house 7. The colors of the houses are [3,2,1,2][3,2,1,2] and its length is 4 houses.

思路:让找最长的序列,序列中任何两个相邻的元素不能相等.

#include <iostream>

using namespace std;

int main(){
int n,k;
//int a[100005];
int ai;
while(cin>>n>>k){
int la=;
int now=;
int maxx=;
cin>>ai;
la=ai;
for(int i=;i<n;i++){
//cin>>a[i];
cin>>ai;
if(ai!=la){
now++;
}else{
now=;
}
la=ai;
maxx= now>maxx?now:maxx;
}
cout<<maxx<<endl;
}
}

CF_2018-2019 Russia Open High School Programming Contest (Unrated, Online Mirror, ICPC Rules, Teams Preferred)的更多相关文章

  1. 2018-2019 Russia Open High School Programming Contest (Unrated, Online Mirror, ICPC Rules, Teams Preferred)

    前言 有一场下午的cf,很滋磁啊,然后又和dalao(见右面链接)组队打了,dalao直接带飞我啊. 这是一篇题解,也是一篇总结,当然,让我把所有的题目都写个题解是不可能的了. 按照开题顺序讲吧. 在 ...

  2. 2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)

    2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) easy: ACE ...

  3. 2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)【A题 类型好题】

    A. Berstagram Polycarp recently signed up to a new social network Berstagram. He immediately publish ...

  4. D. Dog Show 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    http://codeforces.com/contest/847/problem/D 巧妙的贪心 仔细琢磨... 像凸包里的处理 #include <cstdio> #include & ...

  5. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A 思路: 贪心,每次要么选两个最大的,要么选三个,因为一个数(除了1)都可以拆成2和3相加,直到所有的数都相同就停止,这时就可以得到答案了; C: 二分+bfs,二分答案,然后bfs找出距离小于等于 ...

  6. 2014-2015 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    I. Sale in GameStore(贪心) time limit per test 2 seconds memory limit per test 512 megabytes input sta ...

  7. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 几道简单题的题解

    A. Toda 2 题意:给你n个人,每个人的分数是a[i],每次可以从两个人到五个人的使得分数减一,使得最终的分数相等: 思路:假设答案为m:每个人的分数与答案m的差值为d[i],sum为d[i]的 ...

  8. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) J dp 背包

    J. Bottles time limit per test 2 seconds memory limit per test 512 megabytes input standard input ou ...

  9. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) G 优先队列

    G. Car Repair Shop time limit per test 2 seconds memory limit per test 512 megabytes input standard ...

随机推荐

  1. JavaScript 正则表达式基础语法

    前言 正则表达式在人们的印象中可能是一堆无法理解的字符,但就是这些符号却实现了字符串的高效操作.通常的情况是,问题本身并不复杂,但没有正则表达式就成了大问题.javascript中的正则表达式作为相当 ...

  2. Nginx故障排错及一个网站小实例

    Nginx访问403错误: 1.没有首页文件 2.没有权限 例:chmod  700 /application/nginx/html/index.html 3.nginx.conf配置文件和首页文件不 ...

  3. H5取经之路——随便写点儿

    [相对定位] * 1.使用position:relative:设置元素为相对定位的元素: * 2.定位机制: ①相对于自己原来文档流中的的位置定位,当不指定top等定位值时,不会改变元素位置: ②相对 ...

  4. 入门嵌入式选择2440?树莓派?STM32?4412开发板?

    如果了解一下当前IT和物联网发展的形势,就会发现Android工程师越来越受欢迎,相比之下单纯的Linux工程师却逊色不少,当然,Android系统的内核也是Linux的,Linux和Android作 ...

  5. 如何使用AB PLC仿真软件Studio 5000 Logix Emulate

    前言:在学习PLC编程或程序开发过程中,如果身边没有实体PLC,又想验证程序逻辑,这时,仿真软件是不错的选择.针对AB PLC的仿真软件Studio 5000 Logix Emulate,有的同学说: ...

  6. django中的反向解析

    1,定义: 随着功能的增加会出现更多的视图,可能之前配置的正则表达式不够准确,于是就要修改正则表达式,但是正则表达式一旦修改了,之前所有对应的超链接都要修改,真是一件麻烦的事情,而且可能还会漏掉一些超 ...

  7. 重新定义Pytorch中的TensorDataset,可实现transforms

    class TensorsDataset(torch.utils.data.Dataset): ''' A simple loading dataset - loads the tensor that ...

  8. [Kubernetes]编排其实很简单

    什么是编排 Kubernetes中,我们总是在说一个概念:编排. 在[Kubernetes]谈谈Kubernetes的本质这篇文章中,关于"编排"的概念介绍了一下:过去很多集群管理 ...

  9. mysql 客户端连接报错Illegal mix of collations for operation

    服务端用的是utf-8,客户端工具打开表和视图是会报Illegal mix of collations for operation错误,经排查,可以采用以下语句解决 SET character_set ...

  10. ASP.NET Core之中间件

    本文翻译自:http://www.tutorialsteacher.com/core/aspnet-core-middleware 基本概念 ASP.NET Core引入了中间件的概念,中间件是在AS ...