Dominoes (Large)
Time limit1sMemory limit512 MB
Find the fewest pushes (each a domino plus a direction) needed to topple every domino through chain reactions.
- Level
Hard8 of 10
- Topics
- Greedy, Sorting, Dynamic programming, Intervals
- Solved
- No attempts yet
Problem
dominoes stand on a number line. Domino stands at position with height , and no two dominoes share a position.
You may pick one domino and push it to the left or to the right. Pushing a domino at position with height to the left makes every domino at a position with fall to the left. Pushing it to the right makes every domino at a position with fall to the right. A domino that falls this way keeps falling in the same direction and knocks over the dominoes inside its own range. The chain continues until no new domino falls.
Each push picks one domino and one direction. Compute the minimum number of pushes that knocks over all dominoes.
Input
The first line contains . ()
Each of the next lines contains two integers and , the position and the height of one domino, separated by a space. ()
The dominoes are not necessarily given in order of position.
Output
Print the minimum number of pushes that knocks over every domino on the first line.