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

Rijeka

설명

In the far away land there is a big river and a number of villages beside it. Villages are numbered 0
through M, in order along the river. Distance bewteen consecutive villages is exactly 1 mile.
Mirko lives in the village marked with 0. He is in the business of transporting people between villages
with his boat. Today, Mirko will travel from his village to village M, and he will also transport some
people along the way.
There are N people that wish to travel today, and for each of them we know their starting point as well
as their destination. Mirko's boat can accommodate as many people as needed.
Let's say for example that person A is traveling from village 2 to village 8, and B from village 6 to
village 4. Mirko will, as always, start from his village 0, pick up A at village 2, pickup B at 6, go back to 4
and leave B there, proceed to village 8, leave A there, and then continue to his final destination, village
M. This scenario is given in the first test case below.
Write a program that will find the minimum number of miles that Mirko must travel in order to
transport everyone to their destinations and reach village M at the end.

제약

In test cases worth a total of 40% points, \(N \le 5000\) will hold.
In test cases worth a total of 50% points, \(M \le 2000000\) will hold.
EXAMPLE TEST DATA
input
2 10
2 8
6 4
output
14
input
8 15
1 12
3 1
3 9
4 2
7 13
12 11
14 11
14 13
output
27

입력 형식

The first line of input contains integers N and M (\(N \le 300\,000\), \(3 \le M \le 10^{9}\)).
The following N lines contain two integers, starting point and destination for each villagers that want's
to travel today. These number will be in range 0 to M.

출력 형식

Output the minimum number of miles that Mirko must travel.

예제 1
입력
2 10
2 8
6 4
출력
14
예제 2
입력
8 15
1 12
3 1
3 9
4 2
7 13
12 11
14 11
14 13
출력
27
문제 정보

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

출처 COI 2011

평가 및 의견

Rijeka

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

Log in to rate problems.

개별 의견

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

풀이 제출

Rijeka

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