Alien Invaders
Time limit3sMemory limit256 MB
Destroy each alien within its time window using bombs, where a bomb of power R kills all aliens present within distance R at cost R, for minimum total fuel.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Divide and conquer, Intervals, Sorting
- Solved
- No attempts yet
Problem
Aliens have invaded Earth. If you do not defend yourself, you die. Or you get assimilated. You might even get eaten. Nobody is quite sure which.
The aliens attack on a fixed schedule. There are aliens, and alien appears at time at distance and attacks you at time . You therefore have to destroy alien at some time between and , inclusive.
Your weapon is a photon bomb whose blast power you can set to any value. If you set the power to and detonate the bomb, every alien that is on the field at that moment and stands at distance at most dies instantly, and the bomb burns units of fuel. You may detonate a bomb at any time and as many times as you want.
Find the smallest amount of fuel that destroys every alien without letting any of them attack you.
Input
The first line has the number of test cases .
Each test case starts with a line holding the number of aliens . The next lines hold , , for alien , separated by spaces.
Output
For each test case, print the smallest amount of fuel that destroys every alien, one answer per line. The answer is always an integer.