Mountain

시간 제한2초메모리 제한2048 MB

요약
n개의 점이 주어질 때, 기울기 +1과 -1이 번갈아 나타나는 x-단조 꺾은선의 봉우리가 될 수 있는 주어진 점의 최대 개수를 구한다.
난이도

어려움10점 중 8점

유형
정렬, 동적 계획법, 기하, 그리디
정답자
아직 제출이 없습니다

문제

Figure 1 A mountain with four peaks

See Figure 1. What do you see? Yes, it is a mountain. Let’s call such a figure a mountain. To be more precise, a mountain is an xx-monotone polygonal chain consisting of at least two line segments whose slopes alternate between +1+1 and −1−1; the leftmost segment is a half-line (ray) of slope +1+1, and the rightmost segment is a half-line of slope −1−1. Every mountain has one or more peaks, which are endpoints incident to a segment of slope +1+1 to the left and a segment of slope −1−1 to the right; in other words, a peak is a locally highest point. In Figure 1, you can see a mountain consisting of eight segments, and it has four peaks, marked by small dots.

In this problem, you are given a set PP of nn points in the plane as input, and your task is to find a mountain with the maximum number of peaks that are chosen from PP.

Figure 2 Two mountains with four and seven peaks, respectively, chosen from a given set PP of 1515 points

An example is illustrated in Figure 2, in which the input set PP of n=15n = 15 points, marked by small circles, is given, and to the left you can see a mountain with four peaks that belong to PP, while to the right there is a mountain with seven peaks that belong to PP. Since there is no such mountain with eight peaks chosen from PP, the one to the right is a correct answer for the problem. See Sample Input/Output 2 below

입력

Your program is to read from standard input. The input starts with a line containing a single integer nn (1≤n≤500,0001 ≤ n ≤ 500\\,000), where nn is the number of points in the input set PP of points in the plane. In each of the following nn lines, given are two integers xx and yy, both ranging from −106−10^6 to 10610^6, inclusively, that represent the xx- and yy-coordinates of an input point (x,y)(x, y) in PP. You may assume that no two input points have the same coordinates.

출력

Your program is to write to standard output. Print exactly one line. The line should contain an integer that represents the number of peaks of a mountain with the maximum number of peaks that are chosen from PP.

예제3

  1. 예제 1

    입력
    4
    0 0
    1 0
    2 0
    3 0
    
    예상 출력
    4
    
  2. 예제 2

    입력
    15
    0 0
    1 4
    3 2
    6 0
    6 3
    6 5
    9 1
    10 4
    12 5
    13 0
    13 5
    15 2
    18 3
    19 4
    20 1
    
    예상 출력
    7
    
  3. 예제 3

    입력
    17
    10 4
    12 5
    19 4
    6 5
    20 1
    0 0
    1 4
    13 0
    6 0
    6 3
    18 3
    3 2
    9 1
    13 5
    15 2
    20 2
    15 3
    
    예상 출력
    8