|
<p> |
|
Tony plans to open a pizzeria. After researching the pizza market for a long time, he has come up with a prediction for the number of orders that he is going to receive. Tony will keep his pizzeria open for <strong>K</strong> hours a day. And he knows that he is going to get orders for <strong>N</strong> pizzas. Also pizza eaters are very fussy, so the <strong>i</strong><sup>th</sup> pizza must be inserted into an oven at exactly the beginning of the <strong>S<sub>i</sub></strong><sup>th</sup> hour, and taken out of the oven at exactly the end of the <strong>E<sub>i</sub></strong><sup>th</sup> hour. |
|
</p> |
|
|
|
<p> |
|
For this purpose Tony needs to buy some ovens to be able to bake all the ordered pizzas. Each oven is quite large, and can hold several pizzas at the same time. However, due to voltage fluctuations throughout the day, only a certain number of pizzas can be baked simultaneously in each oven at any point of time. Tony has calculated the value <strong>C<sub>i</sub></strong>, for 0 ≤ <strong>i</strong> < <strong>K</strong>, denoting the number of pizzas that can be baked together in an oven during the <strong>i</strong><sup>th</sup> hour. A pizza that has been entered in an oven cannot be taken out of the oven until it has completed its scheduled baking period. |
|
</p> |
|
|
|
<p> |
|
High quality pizza ovens are very costly. Help Tony find out the minimum number of ovens he must buy to complete all orders, and then find an assignment of pizzas to ovens, satisfying all the constraints above. If there are multiple assignments involving the same minimum number of ovens, print the smallest possible assignment according to the ordering defined below. |
|
</p> |
|
|
|
<p> |
|
Here's how you compare two assignments. If <strong>X</strong> is an assignment of pizzas to ovens, let <strong>X</strong>(<strong> i </strong>) denote the set of 0-based pizza indices assigned to oven <strong>i</strong> (oven indices are also 0-based). |
|
</p> |
|
|
|
<p> |
|
If <strong>S</strong> and <strong>T</strong> are two sets of pizza indices, we say that <strong>S</strong> < <strong>T</strong>, if and only if there exists some index <strong>k</strong>, such that : <br /> |
|
* for 0 ≤ <strong>i</strong> < <strong>k</strong>, pizza <strong>#i</strong> either appears both in <strong>S</strong> and <strong>T</strong>, or is missing from both <strong>S</strong> and <strong>T</strong>, and, <br /> |
|
* pizza <strong>#k</strong> is present in<strong> S,</strong> but missing in <strong>T</strong> <br /> |
|
Example: {0, 2, 6} < {0, 3, 4} and {0, 1, 2, 3} < {0, 1, 2} |
|
</p> |
|
|
|
<p> |
|
If <strong>X</strong> and <strong>Y</strong> are two pizza assignments, we say that <strong>X</strong> < <strong>Y</strong>, if and only if there exists some <strong>k</strong>, such that : <br /> |
|
* for 0 ≤ <strong>i</strong> < <strong>k</strong>, <strong>X</strong>(<strong> i </strong>) is identical to <strong>Y</strong>(<strong> i </strong>), and, <br /> |
|
* <strong>X</strong>(<strong> k </strong>) < <strong>Y</strong>(<strong> k </strong>), as per the set ordering defined above. <br /> |
|
Example:<br /> |
|
<strong>X</strong> = [ <strong>X</strong>(0) = {0, 3, 6}, <strong>X</strong>(1) = {1, 4, 5}, <strong>X</strong>(2) = {2, 7} ] <br /> |
|
<strong>Y</strong> = [ <strong>Y</strong>(0) = {0, 3, 6}, <strong>Y</strong>(1) = {1, 4}, <strong>Y</strong>(2) = {2, 5, 7} ] <br /> |
|
Then <strong>X</strong> < <strong>Y</strong>, because <strong>X</strong>(0) = <strong>Y</strong>(0) and <strong>X</strong>(1) < <strong>Y</strong>(1). <br /> |
|
</p> |
|
|
|
|
|
<h3>Input</h3> |
|
<p> |
|
The first line of the input consists of a single integer <strong>T</strong>, the number of test |
|
cases. <br /> |
|
Each test case starts with a line containing the integer <strong>K</strong>, the number of hours the pizzeria will be open. <br /> |
|
The next line of each test case contains <strong>K</strong> integers, <strong>C<sub>0</sub></strong>, <strong>C<sub>1</sub></strong>, ..., <strong>C<sub>K-1</sub></strong>, where <strong>C<sub>i</sub></strong> is the maximum number of pizzas that can be inside any single oven in the <strong>i</strong><sup>th</sup> hour. <br /> |
|
The next line of each test case contains the integer <strong>N</strong>, the number of pizza orders. <br /> |
|
The next <strong>N</strong> lines of each test case contain a pair of integers, <strong>S<sub>i</sub></strong> and <strong>E<sub>i</sub></strong>, the start and end times for baking the <strong>i</strong><sup>th</sup> pizza. <br/> |
|
</p> |
|
|
|
|
|
<h3>Output</h3> |
|
<p> |
|
For each test case <strong>i</strong> numbered from 1 to <strong>T</strong>, output "Case #<strong>i</strong>: ", followed by <strong>N</strong> space separated integers. |
|
The <strong>j</strong><sup>th</sup> integer must denote the 0-based oven index that the <strong>j</strong><sup>th</sup> pizza is assigned to. |
|
</p> |
|
|
|
|
|
<h3>Constraints</h3> |
|
<p> |
|
1 ≤ <strong>T </strong>≤ 20 <br /> |
|
1 ≤ <strong>K</strong> ≤ 24 <br /> |
|
1 ≤ <strong>C<sub>i</sub></strong> ≤ 100 <br /> |
|
1 ≤ <strong>N</strong> ≤ 1000 <br /> |
|
0 ≤ <strong>S<sub>i</sub></strong> ≤ <strong>E<sub>i</sub></strong> < <strong>K</strong> <br /> |
|
</p> |
|
|