#P13372. [GCJ 2011 #1C] Space Emergency
[GCJ 2011 #1C] Space Emergency
题目描述
There's an emergency—in space! You need to send your fleet's flagship as quickly as possible from star to star , traveling through the other stars in increasing numerical order along the way (). Your flagship normally travels at a speed of parsecs per hour.
In addition to sending your flagship, you can order your engineers to build up to speed boosters at different stars. Building a speed booster takes hours, and all speed boosters can be built in parallel. While your flagship travels from a star with a completed speed booster to the next star, its speed is parsec per hour.
If a speed booster is completed at a star while your flagship is traveling from that star to the next one, your flagship will start moving faster as soon as the speed booster is completed.
How many hours does it take your flagship to get to star if you build speed boosters to make it arrive as soon as possible?
输入格式
The first line of the input gives the number of test cases, . lines follow. Each contains integers, , , and , followed by integers , all separated by spaces. is the number of parsecs between star and star , for all integer values of .
For example, with , , , and , the distances between stars are .
输出格式
For each test case, output one line containing "Case #: ", where is the case number (starting from ) and is a single integer: the number of hours it takes to reach star . The answer is guaranteed to always be an integer.
2
2 20 8 2 3 5
1 4 2 2 10 4
Case #1: 54
Case #2: 20
提示
Explanation
In the second case, we can build one speed booster. The distances between stars are . We build the speed booster on the first star. After hours, our flagship has gone parsecs and the speed booster is complete. It takes our flagship another hours to get to star , then more hours to get to star , our destination.
Note: This problem takes place in a universe where the speed of light is much higher than parsec per hour, so we don't have to worry about special relativistic effects.
Limits
- .
- .
- .
- .
- .
- is even.
Small dataset (12 Pts, Test set 1 - Visible)
- .
- .
- Time limit:
303 seconds.
Large dataset (25 Pts, Test set 2 - Hidden)
- .
- .
- Time limit:
606 seconds.