Freedom Dive

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

요약
x좌표 순으로 정렬된 점들이 주어질 때, 각 질의 x0(양 끝 사이, 어떤 점과도 겹치지 않음)에 대해 x0를 사이에 두는 두 점을 잇는 선분이 x0에서 갖는 최소 높이를 기약분수로 구한다.
난이도

어려움10점 중 8점

유형
기하, 이분 탐색, 분할 정복
정답자
아직 제출이 없습니다

문제

On a scenic coastline, there are NN skyscrapers arranged in a line. For each building ii (from 11 to NN), we know its distance from the sea, L_iL\_i, and its height, H_iH\_i. We can model the top of each building as a point in a 2D plane at coordinates (L_i,H_i)(L\_i, H\_i). The buildings are sorted by their distance from the sea, so it's guaranteed that L_i<L_i+1L\_i < L\_{i+1} for all 1≤i<N1 \le i < N.

You are a professional skydiver and have planned a spectacular dive for QQ different days. On the ii-th day (1≤i≤Q1 \le i \le Q), you are given a planned dive location, which is a horizontal coordinate d_id\_i. It is guaranteed that no building is located exactly at d_id\_i.

To prepare for the ii-th day's dive, you must perform the following setup:

  • First, choose two buildings: one building ll located to the left of your dive location (where L_l<d_iL\_l < d\_i) and one building rr located to the right (where L_r>d_iL\_r > d\_i). It is guaranteed that such a pair of buildings always exists.
  • Next, connect the tops of these two buildings, i.e., points (L_l,H_l)(L\_l, H\_l) and (L_r,H_r)(L\_r, H\_r), with a straight rope.
  • Finally, you will make your jump from the point on this rope that is precisely at the horizontal coordinate d_id\_i.

Being a cautious professional, you want to minimize the risk associated with high altitudes. Therefore, for each dive, you must choose the pair of buildings (l,r)(l, r) that results in the lowest possible altitude for the rope at your jump-off coordinate d_id\_i.

Note that the rope is an idealized line segment. It is allowed to pass through or intersect with other buildings; its path is determined only by the two chosen endpoints.

For each of the QQ planned dives, find this minimum possible altitude.

입력

The first line contains a single integer NN — the number of buildings.

The next NN lines describe the buildings. The ii-th of these lines contains two integers, L_iL\_i and H_iH\_i — the distance from the sea and the height of the ii-th building. It is guaranteed that L_1<L_2<⋯<L_NL\_1 < L\_2 < \dots < L\_N.

The next line contains a single integer QQ — the number of planned diving days.

The next QQ lines describe the planned dives. The ii-th of these lines contains a single integer d_id\_i — the horizontal coordinate for that day's dive. It is guaranteed that dd will not be equal to any L_iL\_i.

출력

For each of the QQ dives, output a single line containing two space-separated integers, ss and tt. These two integers must represent the minimum possible starting altitude as an irreducible fraction s/ts/t. If the denominator is 11, you should still print it.

제한

  • 2≤N≤2⋅1052 \le N \le 2 \cdot 10^5
  • 1≤Q≤2⋅1051 \le Q \le 2 \cdot 10^5
  • 1≤L_i,H_i≤1091 \le L\_i, H\_i \le 10^9
  • L_1<d_i<L_NL\_1 < d\_i < L\_N (1≤i≤Q 1 \le i \le Q)

예제2

  1. 예제 1

    입력
    4
    1 4
    4 3
    7 5
    11 2
    7
    2
    3
    5
    6
    8
    9
    10
    
    예상 출력
    11 3
    10 3
    20 7
    19 7
    17 7
    16 7
    15 7
    
  2. 예제 2

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