Convenience Store Part-Timers
Time limit1sMemory limit128 MB
Hire the fewest of N applicants, each working a fixed 8-hour shift starting at a given hour, so every hour of the 24-hour day meets its staffing requirement.
- Level
Medium7 of 10
- Topics
- Greedy, Brute force
- Solved
- No attempts yet
Problem
A convenience store has just opened on the outskirts of town. Jun, the owner, wants to hire enough part-timers to staff the counter. The number of part-timers needed differs by hour of the day: few at night, many during the day, and so on. Jun wants to satisfy every hourly requirement while hiring as few part-timers as possible.
The number of part-timers required in each hour is given as . is the number needed from 0:00 to 1:00, from 1:00 to 2:00, , and from 23:00 to midnight. The requirements are the same every day, and having more part-timers than required in an hour is fine.
people applied. Each applicant works every day for exactly 8 consecutive hours starting at hour (). If the 8 hours cross midnight, they wrap into the next day. For example, starting at 20 covers hours 20, 21, 22, 23, 0, 1, 2, 3. Every hired part-timer shows up on time each day and works their full shift.
Given and , find the minimum number of part-timers Jun must hire so that every hour's requirement is met.
Input
The first line contains the number of test cases, which is at most 20.
Each test case is given as follows. The first line contains 24 integers through separated by spaces (). The second line contains the number of applicants (). Then follow lines, each containing one applicant's start hour ().
Output
For each test case, print the minimum number of part-timers on its own line.
If it is impossible to meet all requirements, print No Solution on that line instead.