Rescue Squad
Time limit1sMemory limit1024 MB
Choose a start hour s so that the window from s:30 to s+M:30 lets the most teams make two site visits, given each team's available hour intervals.
- Level
Medium6 of 10
- Topics
- Intervals, Sliding window, Sorting
- Solved
- No attempts yet
Problem
Junggeuri is the captain of a school rescue squad. Upon hearing that cats are trapped in a basement, the squad decided to go rescue them. However, the squad members are students, so they can only act for hours, the time approved by their teacher. Once they start, they must act for consecutive hours without a break. Junggeuri can choose when to start. If the start time is ( is a non-negative integer), Junggeuri can request activity from :30 to :30.
The school rescue squad consists of several teams. A team's rescue work proceeds as follows.
- The team arrives at the site and assesses the situation.
- The team returns, analyzes the situation, and gathers the necessary supplies.
- The team goes back to the site and completes the rescue.
Each team has a unique number and at least one available time interval. An interval is written , meaning the team can be active from :00 to :59. A team can arrive at or return from the site at any time within its available hours, but once it returns during an interval, it cannot go back to the site during that same interval. Junggeuri only lets teams that can visit the site at least twice join the rescue, and wants as many such teams as possible. Help Junggeuri pick the times so that the most teams can join.
Input
The first line contains , the number of available time intervals, and , the given time, separated by a space.
Each of the next lines contains three integers , , and , separated by spaces, where is one of the available intervals of team .
The available intervals of the same team do not overlap. Precisely, for any two intervals and of the same team, , and if , then .
Output
Print the maximum number of teams that can join the rescue on the first line.
Constraints
- ,
- ,
- All input values are integers.