#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 00 to star NN, traveling through the other stars in increasing numerical order along the way (01N0 \rightarrow 1 \rightarrow \ldots \rightarrow N). Your flagship normally travels at a speed of 0.50.5 parsecs per hour.

In addition to sending your flagship, you can order your engineers to build up to LL speed boosters at different stars. Building a speed booster takes tt hours, and all LL 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 11 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 NN 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, TT. TT lines follow. Each contains integers, LL, tt, NN and CC, followed by CC integers aia_i, all separated by spaces. aia_i is the number of parsecs between star k×C+ik\times C+i and star k×C+i+1k\times C+i+1, for all integer values of kk.

For example, with N=8N=8, C=3C=3, a0=3a_0=3, a1=5a_1=5 and a2=4a_2=4, the distances between stars are [3,5,4,3,5,4,3,5][3, 5, 4, 3, 5, 4, 3, 5].

输出格式

For each test case, output one line containing "Case #xx: yy", where xx is the case number (starting from 11) and yy is a single integer: the number of hours it takes to reach star NN. 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 [10,4][10, 4]. We build the speed booster on the first star. After 44 hours, our flagship has gone 22 parsecs and the speed booster is complete. It takes our flagship another 88 hours to get to star 11, then 88 more hours to get to star 22, our destination.

Note: This problem takes place in a universe where the speed of light is much higher than 11 parsec per hour, so we don't have to worry about special relativistic effects.

Limits

  • 1T1001 \leq T \leq 100.
  • 1C10001 \leq C \leq 1000.
  • CNC \leq N.
  • 1ai1041 \leq a_i \leq 10^4.
  • 0t10110 \leq t \leq 10^{11}.
  • tt is even.

Small dataset (12 Pts, Test set 1 - Visible)

  • 1N10001 \leq N \leq 1000.
  • 0L20 \leq L \leq 2.
  • Time limit: 30 3 seconds.

Large dataset (25 Pts, Test set 2 - Hidden)

  • 1N1061 \leq N \leq 10^6.
  • 0LN0 \leq L \leq N.
  • Time limit: 60 6 seconds.