Logo
(追記) (追記ここまで)

19817번 - Company Merging 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB150937761.600%

문제

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.

입력

The first line contains a single integer $n$ --- the number of companies in the conglomerate (1ドル \le n \le 2 \cdot 10^5$). Each of the next $n$ lines describes a company.

A company description start with an integer $m_i$ --- the number of its employees (1ドル \le m_i \le 2 \cdot 10^5$). Then $m_i$ 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ドル \cdot 10^5$.

출력

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$.

출처

Olympiad > Russian Olympiad in Informatics > Russia Team High School Programming Contest > Russia Team High School Programming Contest 2018 A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /