#P13215. [GCJ 2015 #1A] Mushroom Monster

[GCJ 2015 #1A] Mushroom Monster

题目描述

Kaylin loves mushrooms. Put them on her plate and she'll eat them up! In this problem she's eating a plate of mushrooms, and Bartholomew is putting more pieces on her plate.

In this problem, we'll look at how many pieces of mushroom are on her plate at 1010-second intervals. Bartholomew could put any non-negative integer number of mushroom pieces down at any time, and the only way they can leave the plate is by being eaten.

Figure out the minimum number of mushrooms that Kaylin could have eaten using two different methods of computation:

  1. Assume Kaylin could eat any number of mushroom pieces at any time.
  2. Assume that, starting with the first time we look at the plate, Kaylin eats mushrooms at a constant rate whenever there are mushrooms on her plate.

For example, if the input is 1010 55 1515 55:

With the first method, Kaylin must have eaten at least 1515 mushroom pieces: first she eats 55, then 1010 more are put on her plate, then she eats another 1010. There's no way she could have eaten fewer pieces.

With the second method, Kaylin must have eaten at least 2525 mushroom pieces. We can determine that she must eat mushrooms at a rate of at least 11 piece per second. She starts with 1010 pieces on her plate. In the first 1010 seconds, she eats 1010 pieces, and 55 more are put on her plate. In the next 55 seconds, she eats 55 pieces, then her plate stays empty for 55 seconds, and then Bartholomew puts 1515 more pieces on her plate. Then she eats 1010 pieces in the last 1010 seconds.

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each will consist of one line containing a single integer NN, followed by a line containing NN space-separated integers mim_i; the number of mushrooms on Kaylin's plate at the start, and at 1010-second intervals.

输出格式

For each test case, output one line containing "Case #xx: yy zz", where xx is the test case number (starting from 11), yy is the minimum number of mushrooms Kaylin could have eaten using the first method of computation, and zz is the minimum number of mushrooms Kaylin could have eaten using the second method of computation.

4
4
10 5 15 5
2
100 100
8
81 81 81 81 81 81 81 0
6
23 90 40 0 100 9
Case #1: 15 25
Case #2: 0 0
Case #3: 81 567
Case #4: 181 244

提示

Limits

  • 1T1001 \leq T \leq 100.

Small dataset(7 Pts)

  • Time limit: 240 5 seconds.
  • 2N102 \leq N \leq 10.
  • 0mi1000 \leq m_i \leq 100.

Large dataset(8 Pts)

  • Time limit: 480 10 seconds.
  • 2N10002 \leq N \leq 1000.
  • 0mi100000 \leq m_i \leq 10000.