Freedom Dive
시간 제한1초메모리 제한1024 MB
x좌표 순으로 정렬된 점들이 주어질 때, 각 질의 x0(양 끝 사이, 어떤 점과도 겹치지 않음)에 대해 x0를 사이에 두는 두 점을 잇는 선분이 x0에서 갖는 최소 높이를 기약분수로 구한다.
문제
On a scenic coastline, there are skyscrapers arranged in a line. For each building (from to ), we know its distance from the sea, , and its height, . We can model the top of each building as a point in a 2D plane at coordinates . The buildings are sorted by their distance from the sea, so it's guaranteed that for all .
You are a professional skydiver and have planned a spectacular dive for different days. On the -th day (), you are given a planned dive location, which is a horizontal coordinate . It is guaranteed that no building is located exactly at .
To prepare for the -th day's dive, you must perform the following setup:
- First, choose two buildings: one building located to the left of your dive location (where ) and one building located to the right (where ). It is guaranteed that such a pair of buildings always exists.
- Next, connect the tops of these two buildings, i.e., points and , with a straight rope.
- Finally, you will make your jump from the point on this rope that is precisely at the horizontal coordinate .
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 that results in the lowest possible altitude for the rope at your jump-off coordinate .
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 planned dives, find this minimum possible altitude.
입력
The first line contains a single integer — the number of buildings.
The next lines describe the buildings. The -th of these lines contains two integers, and — the distance from the sea and the height of the -th building. It is guaranteed that .
The next line contains a single integer — the number of planned diving days.
The next lines describe the planned dives. The -th of these lines contains a single integer — the horizontal coordinate for that day's dive. It is guaranteed that will not be equal to any .
출력
For each of the dives, output a single line containing two space-separated integers, and . These two integers must represent the minimum possible starting altitude as an irreducible fraction . If the denominator is , you should still print it.
제한
- ()