Doubles Horseback Wrestling

면접 대비

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

요약
각 선수의 레이팅 구간이 주어질 때 두 레이팅 합이 s가 되도록 짝을 지어, 겹치지 않는 짝의 수를 최대로 만든다.
난이도

보통10점 중 7점

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

문제

The Nomadic Games Exploratory Committee (NGEC) is floating the idea of a doubles horseback wrestling tournament with pairs of riders astride single horses. They have advertised a pilot tournament, and nn eager riders have signed up to compete! So now the NGEC needs to pair the riders in order to make the tournament both fair and exciting.

The Central Asian Audaryspak League (CAAL) maintains a list of all horseback wrestlers and their ratings. From their previous experience with ordinary horseback wrestling, the NGEC has decided that the pairs are best balanced if the ratings of their two riders add up to a particular integer, ss.

For obscure licensing reasons, the CAAL refuses to release the exact rating of each rider. But the NGEC has some good estimates, knowing that any rider ii’s true rating r_ir\_i lies in an interval \[l_i,u_i]\[l\_i, u\_i]. So the NGEC would consider pairing two riders ii and jj if there are ratings r_i∈\[l_i,u_i]r\_i \in \[l\_i, u\_i] and r_j∈\[l_j,u_j]r\_j \in \[l\_j , u\_j] such that r_i+r_j=sr\_i + r\_j = s.

The NGEC wants to form as many non-intersecting pairs of riders as possible. You need to help them.

입력

The first line contains two integers nn and ss (2≤n≤2⋅1052 ≤ n ≤ 2 \cdot 10^5, 1≤s≤1091 ≤ s ≤ 10^9), denoting the number of riders and the desired sum of ratings of riders in a pair. Riders are numbered 11 to nn. This is followed by nn lines, where the iith line contains two integers l_il\_i and u_iu\_i (1≤l_i≤u_i≤1091 ≤ l\_i ≤ u\_i ≤ 10^9), denoting the rating range of the iith rider.

출력

Output kk, the maximum number of riding pairs that can be formed, followed by kk pairs of integers, denoting the numbers of the riders forming each pair. If there are multiple ways to pair off the riders, output any one.

예제1

  1. 예제 1

    입력
    6 10
    6 7
    1 4
    2 2
    3 8
    5 7
    9 9
    
    예상 출력
    2
    6 2
    3 4