Domino
Time limit1sMemory limit128 MB
Topple one domino left or right and count how many fall in the longest chain reaction.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Binary search, Segment tree
- Solved
- No attempts yet
Problem
For Christmas, Jarek received a set of dominoes of different heights and stood them all upright in a single row.
If Jarek topples a domino of height at position to the right, every domino at positions falls to the right. Likewise, toppling a domino of height at position to the left makes every domino at positions fall to the left. Each domino that falls topples the following dominoes in the same direction (a chain reaction).
Given the position and height of every domino, find the maximum number of dominoes that fall when a single domino is toppled in either direction.
Input
The first line contains the number of test cases ().
The first line of each test case contains the number of dominoes (). Each of the next lines contains two integers and (), the position and height of a domino. The positions are given in increasing order.
Output
For each test case, print on its own line the maximum number of dominoes that can be toppled by knocking over a single domino.