Space Emergency (Small)
Time limit5sMemory limit512 MB
Place up to two speed boosters that all finish at time t so the flagship moving from star 0 through every star in order reaches star N earliest.
- Level
Medium5 of 10
- Topics
- Brute force, Simulation
- Solved
- No attempts yet
Problem
There is an emergency in space. You have to send your fleet's flagship from star 0 to star as fast as you can, and it passes through every star in between in increasing order of number: 0, then 1, then 2, and so on up to . The flagship normally travels at 0.5 parsecs per hour.
Separately from sending the flagship, you can order your engineers to build up to speed boosters at distinct stars. One booster takes hours to build, and all of them are built at the same time. While the flagship travels from a star with a finished booster to the next star, its speed is 1 parsec per hour.
If the booster at a star finishes while the flagship is already on its way from that star to the next one, the flagship speeds up the moment the booster finishes.
If you place the boosters so that the flagship reaches star as early as possible, how many hours does the trip take?
Input
The first line contains the number of test cases . Each of the next lines contains the integers , , and , followed by integers , all separated by spaces. is the distance in parsecs between star and star , and the same value repeats for every integer .
For example, with , , , and , the distances between consecutive stars are [3, 5, 4, 3, 5, 4, 3, 5].
Limits
- is even
Output
For each test case, print one line in the form Case #x: y, where is the test case number starting from 1 and is the number of hours it takes to reach star . The answer is guaranteed to be an integer.
Note
Take the case , , with distances [10, 4]. Build the booster at star 0. After 4 hours the flagship has covered 2 parsecs and the booster is finished. It covers the remaining 8 parsecs at 1 parsec per hour, so it reaches star 1 eight hours later, and since star 1 has no booster it spends another 8 hours on the 4 parsecs to star 2, the destination. The trip takes 20 hours in total.
This problem takes place in a universe where the speed of light is far above 1 parsec per hour, so you do not have to worry about special relativistic effects.