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

Cestarine

Platinum II 플래티넘 II
난이도
1s
시간 제한
32MB
메모리 제한
1
맞았습니다!!
1
제출 수
100.0%
정답률
레이팅

의견: 0

설명

In a single day, \(N\) of Luka's trucks travel a specific highway. The highway has a number of exits and entrances. An exit with a particular number is in the same location as the entrance with that number.

Upon entering the highway, a truck driver receives a ticket which indicates the entrance he used. When exiting, the driver pays a toll equal to the absolute difference of the entrance and exit numbers. For example, if a ticket says he used entrance \(30\), then exiting at exit \(12\) will cost him \(18\).

Luka has figured out a way to save toll money that his company daily spends. Any two drivers can meet on the highway and exchange tickets, even if their routes don't overlap. Tickets can be exchanged an arbitrary number of times.

However, a driver cannot use an exit if his ticket says he used the same entrance, since that would be suspicious.

Write a program that calculates the least total amount of tolls that the drivers can achieve by exchanging tickets.

제약
입력 형식

The first line contains the integer \(N\) (\(1 \le N \le 100\,000\)), the number of trucks.

Each of the following \(N\) lines contains two distinct integers between \(1\) and \(1\,000\,000\). These are in order the entrance and exit numbers of one truck.

No two trucks will use the same highway entrance or the same exit.

출력 형식

Output the least total amount of tolls Luka's company must pay.

Note: use 64-bit integer types (long long in C/C++, int64 in Pascal).

서브태스크
서브태스크점수설명

Subtask 1

80점
예제 1
입력
3
3 65
45 10
60 25
출력
32
설명

The first and third drivers exchange tickets, then the second and third do. The drivers end up with tickets 60, 3, 45, for a total of |65-60| + |10-3| + |25-45| = 32.

예제 2
입력
3
5 5
6 7
8 8
출력
5
문제 정보

riseoj 작성

출처 COCI 2007/2008 Contest 6

평가 및 의견

Cestarine

개요
출제자 난이도 Platinum II 플래티넘 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Cestarine

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