ICPC Team Generation

면접 대비

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

요약
순위가 매겨진 n명의 참가자가 각자 팀원의 순위 범위를 지정할 때, 서로 허용하는 세 명으로 이루어진 팀의 최대 개수를 구한다.
난이도

보통10점 중 7점

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

문제

Vi is a coach for her university's ICPC organization and is working on creating teams for their upcoming regional contest. They recently competed in the North America Qualifier and Vi is using the results as well as each person's preferences to create as many teams of three as possible to send to regionals.

More specifically, nn people from Vi's university competed in the North America Qualifier (NAQ), and each person got a unique rank from 11 to nn. The person at rank rr has two parameters, a_ra\_r and b_rb\_r, where a_r≤r≤b_ra\_r \le r \le b\_r, indicating that their two teammates must have a rank between a_ra\_r and b_rb\_r, inclusive. Teams must have exactly three people.

Due to the collaborative environment, Vi notes that for every pair of individuals at ranks ii and jj, if i<ji < j, then a_i≤a_ja\_i \le a\_j and b_i≤b_jb\_i \le b\_j.

Compute the maximum number of teams that Vi can send to regionals

입력

The first line of input contains a single integer nn (3≤n≤503 \le n \le 50), which is the number of competitors in the local contest.

Each of the next nn lines contains two integers a_ra\_r and b_rb\_r (a_r≤r≤b_ra\_r \le r \le b\_r), where rr is the competitor's rank. These are the limits of the ranks of the competitors that can be teamed with this competitor. The competitors are given in rank order, from 11 to nn. If i<ji < j, then a_i≤a_ja\_i \le a\_j and b_i≤b_jb\_i \le b\_j.

출력

Output a single integer, which is the maximum number of teams Vi can send to the regional contest.

예제1

  1. 예제 1

    입력
    6
    1 2
    1 2
    2 5
    2 6
    2 6
    5 6
    
    예상 출력
    1