ICPC Team Generation
Time limit1sMemory limit1024 MB
Form the most teams of three where each member's two teammates have ranks inside that member's [a, b] range, with a and b nondecreasing in rank.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Intervals
- Solved
- No attempts yet
Problem
Vi is a coach for her university's ICPC organization. She is building teams for the upcoming regional contest. Her university recently competed in the North America Qualifier (NAQ), and Vi uses the results and each person's preferences to form as many teams of three as possible for regionals.
There are people from the university who competed in the NAQ. Each person has a unique rank from to . The person at rank has two parameters, and , with . Their two teammates must have a rank between and , inclusive. Teams must have exactly three people.
Because of the collaborative environment, for every pair of people at ranks and with , and hold.
Compute the maximum number of teams Vi can send to regionals.
Input
The first line contains a single integer (), the number of competitors in the local contest.
Each of the next lines contains two integers and (), where is the competitor's rank. These are the limits on the ranks of the teammates for this competitor. Competitors are given in rank order, from to . If , then and .
Output
Output a single integer, the maximum number of teams Vi can send to the regional contest.