#P3364. Cool loves touli

Cool loves touli

Description

One day, while Cool and touli were participating in a multi-school contest, they started discussing what kind of lineup would be strong. Cool thought that in a lineup, after sorting heroes by level from low to high, their attack values should be increasing. Cool then asked touli what the maximum possible size of such a lineup would be.

However, touli felt this question was too trivial, so he changed the condition: after sorting by level from low to high, for any two adjacent heroes in this order, the lower-level hero’s attack must be no greater than the higher-level hero’s strength, and the higher-level hero’s attack must be no less than the lower-level hero’s intelligence.

Now Cool wants to know, among several heroes, what is the maximum number of heroes that can be selected to form such a lineup.

Input Format

The first line nn indicates there are nn heroes.

The next nn lines each contain 44 integers l,s,w,al, s, w, a, representing that hero’s level, strength, intelligence, and attack, respectively.

Output Format

A single integer, the maximum number of heroes that can be selected.

3
1 2 3 1
2 1 2 2
3 1 3 3
2

Hint

Selecting the 11st and 33rd heroes satisfies the condition. For the 11st and 22nd heroes, the 22nd hero’s attack is less than the 11st hero’s intelligence, so they cannot both be in the lineup.

Constraints: n105n \leq 10^5, l,s,w,a108l, s, w, a \le 10^8, and the ll values are pairwise distinct.

Translated by ChatGPT 5