#P3364. Maximum Valid Hero Formation
Maximum Valid Hero Formation
Maximum Valid Hero Formation
You are given n heroes. Each hero has four attributes:
- Level
- Attack
- Strength
- Intelligence
You want to form a formation by selecting some heroes. In the formation, the heroes are sorted in increasing order by their levels. For any two consecutive heroes, say A (with lower level) and B (with higher level), the following conditions must be satisfied:
- A.attack \(\leq\) B.strength
- B.attack \(\geq\) A.intelligence
Your task is to select as many heroes as possible forming such a valid formation and output the maximum number of heroes that can be chosen.
Note: It is allowed to select just one hero (which trivially satisfies the conditions).
inputFormat
The input begins with a line containing a single integer n (1 \(\leq n \leq 10^5\) typically), representing the number of heroes.
Each of the following n lines contains four space-separated integers: level, attack, strength, and intelligence of a hero.
outputFormat
Output a single integer, the maximum number of heroes that can form a valid formation satisfying the given conditions.
sample
3
1 5 6 4
2 7 8 5
3 6 10 3
3