아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Paranoid Cows

면접 대비

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

요약
구간들이 중첩(Ai < Aj < Bj < Bi)하지 않는 가장 긴 접두사의 길이를 구한다.
난이도

보통10점 중 4점

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

문제

Farmer John's N cows (1 ≤ N ≤ 100,000) are self-conscious about their milk output. A cow who does not produce much milk is likely to be teased by the other cows.

FJ has designed a milking schedule for the cows in which every cow i (i is a cow index in the range 1..N) is assigned to an interval of time A[i]..B[i] (0 ≤ A[i] < B[i] ≤ 1,000,000,000). The cow must enter the barn at time A[i] for milking and depart from the barn at time B[i]. The door to the barn is narrow and can accommodate at most one cow at a time, so FJ has designed his schedule so that no two cows enter or leave at the same time.

Suppose the milking interval for some cow i contains the interval for some other cow j. That is, A[i] < A[j] < B[j] < B[i]. In this case, we say these two intervals "nest". Nesting intervals are bad, since in this case cow i is in the barn for the entire duration of cow j's milking and as a result, cow i can spy on cow j and determine her milk output. Since cows are paranoid about other cows knowing their milk output, FJ hopes his schedule does not contain any nested intervals.

Please help FJ by determining the largest index K (1 ≤ K ≤ N) such the intervals of cows 1..K have no occurrences of nesting.

입력

  • Line 1: The number of cows, N
  • Lines 2..N+1: Two space-separated integers that are respectively the start and end times of a cow's milking interval

출력

  • Line 1: A single integer, k.

예제1

  1. 예제 1

    입력
    5
    7 20
    1 4
    3 12
    6 10
    0 3
    
    예상 출력
    3