#Q90. 「一本通 3.4 例 2」出纳员问题
「一本通 3.4 例 2」出纳员问题
Description
Original problem from: Asia 2000, problem statement can be found at ZOJ 1420.
A supermarket in Tehran operates 24 hours a day and requires a team of cashiers to meet its needs. The supermarket manager has hired you to solve the problem—the supermarket requires different numbers of cashiers at different times of the day (e.g., only a few at midnight, but many in the afternoon) to provide quality service to customers. He wishes to hire the minimum number of cashiers.
The manager has provided you with the minimum number of cashiers required for each hour of the day—. Here, represents the minimum number of cashiers needed from midnight to 1:00 AM, represents the number needed from 1:00 AM to 2:00 AM, and so on. These requirements are the same every day. There are applicants for the job, and each applicant works exactly 8 consecutive hours in a 24-hour period, starting at a specific time denoted by . That is, if the -th applicant is hired, they will work continuously for 8 hours starting from time .
Your task is to write a program that takes and as inputs (all non-negative integers) and calculates the minimum number of cashiers needed to meet the requirements. At any given time, there may be more cashiers working than the corresponding .
Input Format
The first line contains the number of test cases .
For each test case, the first line consists of 24 integers representing ;
The next line contains a positive integer , the number of applicants;
The following lines each contain an integer .
There is no blank line between test cases.
Output Format
For each test case, output one line containing an integer representing the minimum number of cashiers needed. If no solution exists, output No Solution.
Sample 1
1
1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
5
0
23
22
1
10
1
Constraints & Notes
For all data, , , , and .