아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Lab planning

시간 제한1초메모리 제한1024 MB

요약
각 그룹 내부의 실험 순서는 고정한 채, 모든 그룹의 첫 실험 시작부터 마지막 실험 종료까지의 대기 시간 합이 최대가 되도록 순서를 정한다.
난이도

보통10점 중 6점

유형
그리디, 정렬
정답자
아직 제출이 없습니다

문제

Ah, university. A bastion of knowledge, the Mecca of education, and the core of bureaucracy.

Wille and Kaski are currently waiting in a computer lab to present a lab in a course. In total, there are NN groups waiting to present their lab. Group ii is going to present m_im\_i different labs, where lab jj takes a_i,ja\_{i, j} minutes.

To be fair, all groups need to wait a really long time to present. There is only a single teacher taking presentations, and letting each group present all their labs in a single go would mean that they don't have to wait unnecessarily for other groups! Therefore, the teacher takes presentations in a seemingly arbitrary order...

Kashi has had enough. She wants to go home and play Pokémon, and is complaining about the inefficiencies in the presentation scheme. To demonstrate how inefficient the system is, she'll compute the longest possible total waiting time, and show just how close the teacher's system is to this value.

Assume that a group starts presenting their first lab at time aa, and completes their final lab at time bb. Then its waiting time is b−ab - a. The total waiting time is the sum of the waiting time over all groups.

The order in which a group must present its labs must be the same as the order they are given in the input.

입력

The first line contains a single integer N≥1N \ge 1.

Then follow NN lines, each containing first the number m_i≥1m\_i \ge 1, and then m_im\_i integers a_i,ja\_{i,j}, all between 1 och 60.

출력

You should output a single number: the longest possible total waiting time for the students over all possible presentation orders.

제한

  • The sum of all the m_im\_i is at most 100,000100\\,000.

힌트

In the given sample, three groups need to present their labs: the first group has labs taking 5 and 15 minutes, the second group takes 10 and 20 minutes, and the third group has a single lab taking an entire hour.

If we choose the order 5,10,60,20,155, 10, 60, 20, 15, the third group will wait only for 60 minutes. The second group will, besides their own labs, have to wait for the lab of the third group, and therefore take 10+60+20=9010+60+20 = 90 minutes. The first group will instead take 5+10+60+20+15=1105 + 10 + 60 + 20 + 15 = 110 minutes.

The sum of this is 60+90+110=26060 + 90 + 110 = 260 minutes.

Note that the order 10, 15, 60, 20, 5 would have resulted in a worse time of 265265, but this is not allowed: group 1 may not present their second lab before their first.

예제1

  1. 예제 1

    입력
    3
    2 5 15
    2 10 20
    1 60
    
    예상 출력
    260