Chain Detonation
InterviewTime limit2sMemory limit512 MB
Place one extra bomb past the last one with unlimited power to destroy as many not-yet-detonated bombs, minimizing the duds among the original bombs.
- Level
Medium6 of 10
- Topics
- Greedy, Intervals, Implementation
- Solved
- No attempts yet
Problem
A demolition crew placed bombs in a row. The bombs are numbered to from left to right. Bomb sits at coordinate and has destructive power .
Every timer was set to the same duration, but the crew planted the bombs starting from the right, so a bomb further to the right goes off slightly earlier. The detonation order is bomb , bomb , ..., bomb .
When bomb detonates, it destroys everything within distance to its left, that is, everything in the coordinate interval . Bombs that have not gone off yet are destroyed too. A destroyed bomb never detonates, and it counts as a dud.
To cut down on duds you plant one extra bomb. You may place it at any coordinate greater than and give it as much destructive power as you want, and it always detonates before every bomb that is already on the ground. Bombs destroyed by the extra bomb count as duds too. You may also place the extra bomb so that it destroys nothing.
Find the smallest number of duds you can end up with after planting one extra bomb.
Input
The first line contains the number of bombs ().
Each of the next lines contains the coordinate () and the destructive power () of bomb , separated by a space. The coordinates are given in increasing order, so , and no two bombs share a coordinate.
Output
Print, on one line, the smallest number of duds that one extra bomb can leave.