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

21828번 - Loop Town 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 512 MB64391967.857%

문제

Some cities have complicated road networks that require advanced graph theory to analyze. But not Loop Town! Loop Town has a single circular road that loops around the town. It has N residents that live in N distinct houses located around the road. The town also has N offices, and each resident works at a distinct office.

The road in Loop Town has length L. The location of each building will be represented by an integer between 0 and L − 1. Since the road is circular, the positions 0 and L − 1 are adjacent. It is guaranteed that the locations of all 2N buildings will be distinct.

Every morning, all N residents simultaneously exit their houses onto the road. They then need to walk along the road to the entrance of the office where they work. When each resident has reached the entrance of their office, they all enter simultaneously.

However, a pandemic has now come to Loop Town, disrupting this usual routine. To prevent the spread of disease, residents must now observe social distancing while walking to work. Since the loop road is rather narrow, this means that it is far more inconvenient for two people to cross each other on their way to work (one person must temporarily step off the path to let the other pass). What is the minimum total number of crossings, assuming all the residents work together to achieve this?

입력

The first line contains the two integers N and L (1 ≤ N ≤ 1 000 000, 1 ≤ L ≤ 109).

The i-th of the next N lines contains the two integers ai and bi (0 ≤ ai, bi < L), where ai and bi represent the locations of the i-th resident’s house and office respectively. It is guaranteed that all 2N locations are distinct.

출력

On a single line, output the minimum total number of crossings.

제한

예제 입력 1

3 100
10 50
30 20
60 40

예제 출력 1

0

Since the road is circular, nobody needs to cross each other.

예제 입력 2

4 100
30 70
10 12
60 75
90 50

예제 출력 2

1

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2021 > CCO 2021 6번

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

출처

대학교 대회

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

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