RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
ICPC00068

L. Swap Space

Unrated 레이팅 미적용
난이도
6s
시간 제한
1024MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

You administer a large cluster of computers with hard drives that use various file system types to store data. You recently decided to unify the file systems to the same type. That is quite a challenge since all the drives are currently in use, all of them are filled with important data to the limits of their capacities, and you cannot afford to lose any of the data. Moreover, reformatting a drive to use a new file system may significantly change the drive’s capacity. To make the reformat possible, you will have to buy an extra hard drive. Obviously, you want to save money by minimizing the size of such extra storage. You can reformat the drives in any order. Prior to reformatting a drive, you must move all data from that drive to one or more other drives, splitting the data if necessary. After a drive is reformatted, you can immediately start using it to store data from other drives. It is not necessary to put all the data on the same drives they originally started on – in fact, this might even be impossible if some of the drives have smaller capacity with the new file system. It is also allowed for some data to end up on the extra drive. As an example, suppose you have four drives \(A\), \(B\), \(C\), and \(D\) with drive capacities 6, 1, 3, and 3 GB. Under the new file system, the capacities become 6, 7, 5, and 5 GB, respectively. If you buy only 1 GB of extra space, you can move the data from drive \(B\) there and then reformat drive \(B\). Now you have 7 GB free on drive \(B\), so you can move the 6 GB from drive \(A\) there and reformat drive \(A\). Finally, you move the six total gigabytes from drives \(C\) and \(D\) to drive \(A\), and reformat \(C\) and \(D\).

제약
입력 형식

The input begins with a line containing one integer \(n\) (\(1 \le n \le 10^{6}\)), which is the number of drives in your cluster. Following this are \(n\) lines, each describing a drive as two integers \(a\) and \(b\), where \(a\) is the capacity with the old file system and \(b\) is the capacity with the new file system. All capacities are given in gigabytes and satisfy \(1 \le a\), \(b \le 10^{9}\). (One thousand petabytes should be enough for everyone, right?)

출력 형식

Display the total extra capacity in gigabytes you must buy to reformat the drives.

예제 1
입력
4
6 6
1 7
3 5
3 5
출력
1
예제 2
입력
4
2 2
3 3
5 1
5 10
출력
5
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC World Finals 2016

평가 및 의견

L. Swap Space

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

L. Swap Space

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8