| <p> | |
| You've been put in charge of creating the problems for a certain high-profile programming contest series. | |
| </p> | |
| <p> | |
| The series will consist of one or more contests of exactly 4 problems each. Every problem has a difficulty rating (an integer between 1 and 100, inclusive), | |
| and the ratings of the 4 problems in each contest must be strictly increasing, but with a difference of no more than 10 between consecutive problems. | |
| In other words, if the problems in a contest have difficulties | |
| <strong>a</strong>, <strong>b</strong>, <strong>c</strong>, and <strong>d</strong> (in order), then the inequalities | |
| <strong>a</strong> < <strong>b</strong> < <strong>c</strong> < <strong>d</strong>, | |
| <strong>b</strong> - <strong>a</strong> ≤ 10, | |
| <strong>c</strong> - <strong>b</strong> ≤ 10, | |
| <strong>d</strong> - <strong>c</strong> ≤ 10 must all hold. | |
| </p> | |
| <p> | |
| You've been given an ordered list of <strong>N</strong> problems to use. Being an experienced problemsetter, you may also write some new problems to insert | |
| at any positions in the list, each with an integer difficulty between 1 and 100, inclusive. The final list of problems must still include the original | |
| <strong>N</strong> problems in their original order, though (with your new problems optionally mixed in). | |
| </p> | |
| <p> | |
| Once the problem list is finalized, the first 4 problems (in order) will form a contest, the next 4 problems will form another contest, and so on. | |
| Note that the number of problems in the list must be divisible by 4, and that each of the contests formed must feature a valid ordered set of 4 problems. | |
| What's the minimum number of additional problems you must write in order to create a set of valid contests? | |
| </p> | |
| <h3>Input</h3> | |
| <p> | |
| Input begins with an integer <strong>T</strong>, the number of contest series you need to create. | |
| For each series, there is first a line containing the integer <strong>N</strong>, then a line containing <strong>N</strong> | |
| space-separated integers, the <strong>i</strong>th of which is <strong>D<sub>i</sub></strong>, | |
| the difficulty rating of the <strong>i</strong>th existing problem. | |
| </p> | |
| <h3>Output</h3> | |
| <p> | |
| For the <strong>i</strong>th series, print a line containing "Case #<strong>i</strong>: " followed by | |
| the minimum number of additional problems you'll need to write. | |
| </p> | |
| <h3>Constraints</h3> | |
| <p> | |
| 1 ≤ <strong>T</strong> ≤ 50 <br /> | |
| 1 ≤ <strong>N</strong> ≤ 100,000 <br /> | |
| 1 ≤ <strong>D<sub>i</sub></strong> ≤ 100 <br /> | |
| </p> | |
| <h3>Explanation of Sample</h3> | |
| <p> | |
| In the first series, the four problems given are already a valid contest, so no new problems need to be written. In the second series, the four existing problems most | |
| certainly do not form a valid contest, due to the gap between the third and fourth ones - one possible way to salvage the situation is to add three new problems with | |
| difficulties 30, 29, and 30 after the third problem, as well as a problem with difficulty 42 at the end, creating two valid contests: [15, 20, 25, 30] and [29, 30, 40, 42]. | |
| </p> | |