Rocky Mountain

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

요약
꼭짓점 하나가 최고봉인 산맥의 꺾은선이 주어질 때, 최고봉에서 직선 케이블로 닿을 수 있는 왼쪽의 가장 낮은 지점과 오른쪽의 가장 낮은 지점을 각각 구한다.
난이도

보통10점 중 7점

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

문제

The Rocky Mountain Cable (RMC) company is planning to run cables from the top peak of the Rocky Mountains to lower points in the mountain range, so that cable cars can be used to transport tourists to the highest peak. A cable must connect from one of the potential sites to the highest peak in a straight line, but the cable cannot cross any part of the mountain range. However, the cable may coincide with a slope.

In order to serve the most number of tourists, it is desirable to connect the cable from the highest peak to the lowest possible site. Help the company determine the best possible site on the left and the right of the highest peak. If there are ties, choose the leftmost site on the left, and the rightmost site on the right.

The mountain range is specified by NN sites (x_i,y_i)(x\_i, y\_i). One of these sites is the unique highest peak (x_p,y_p)(x\_p, y\_p) such that 1<p<N1 < p < N and y_p>y_iy\_p > y\_i for all i≠pi \neq p. Note that the highest peak cannot be the first or the last site. The entire mountain range is described by straight line segments connecting (x_i,y_i)(x\_i, y\_i) to (x_i+1,y_i+1)(x\_{i+1}, y\_{i+1}) for 1≤i<N1 \leq i < N, such that x_i<x_i+1x\_i < x\_{i+1}.

입력

The first line of input contains the integer NN (3≤N≤5⋅1053 \leq N \leq 5 \cdot 10^5) which is the number of sites. The next NN lines each contains two integers x_ix\_i and y_iy\_i, specifying the NN sites. The coordinates satisfy 0≤x_i,y_i≤1090 \leq x\_i, y\_i \leq 10^9. It is guaranteed that there is a unique highest peak, and that x_i<x_i+1x\_i < x\_{i+1} for all 1≤i<N1 \leq i < N.

출력

On the first line, output the coordinates of the best site to the left of the highest peak. On the second line, output the coordinates of the best site to the right of the highest peak.

예제3

  1. 예제 1

    입력
    5
    10 10
    20 20
    30 40
    40 30
    50 0
    
    예상 출력
    10 10
    40 30
    
  2. 예제 2

    입력
    5
    10 10
    20 20
    30 30
    40 20
    50 10
    
    예상 출력
    10 10
    50 10
    
  3. 예제 3

    입력
    10
    10 10
    20 35
    30 20
    40 40
    50 45
    60 40
    70 30
    80 40
    90 20
    1000 10
    
    예상 출력
    20 35
    1000 10