#P7503. Cheating Exam Segments

    ID: 20698 Type: Default 1000ms 256MiB

Cheating Exam Segments

Cheating Exam Segments

There are (n) candidates taking an exam. The (i)th candidate currently has a score (a_i). To pass the exam, the candidate needs at least (l_i) points, but in order not to arouse suspicion, the candidate's score must not exceed (r_i).\n\nYou are allowed to conduct several cheating sessions. All the cheating sessions are held simultaneously, so no candidate can participate in more than one session. Each cheating session is performed on a contiguous segment of candidates. In a cheating session covering candidates from index (i) to (j), all candidates in that segment have their scores raised to (S = \max{a_i, a_{i+1}, \dots, a_j}). However, for every candidate (k) in ([i, j]), it must hold that (S \le r_k) (so as not to raise suspicion). After the cheating, a candidate in the session passes if and only if (S \ge l_k). For candidates not involved in any cheating session, their score remains (a_k) and they pass the exam only if (l_k \le a_k \le r_k).\n\nYour task is to choose a set of disjoint contiguous segments on which to perform the cheating so that the number of candidates passing the exam is maximized. Output the maximum number of candidates that can pass under these conditions.\n\nNote: All formulas are provided in (\LaTeX) format.

inputFormat

The first line of input contains an integer (n) ( (1 \le n \le 10^3)) representing the number of candidates. Each of the next (n) lines contains three integers (a_i), (l_i), and (r_i) (with (0 \le a_i, l_i, r_i \le 10^9)) describing the current score, the minimum score needed to pass, and the maximum allowed score for the (i)th candidate respectively.

outputFormat

Output a single integer: the maximum number of candidates that can pass the exam when you optimally conduct the cheating sessions.

sample

5
50 60 100
70 70 80
60 60 100
90 80 90
40 50 60
4