#P10941. Supermarket Cashier Scheduling

    ID: 12990 Type: Default 1000ms 256MiB

Supermarket Cashier Scheduling

Supermarket Cashier Scheduling

A supermarket in Tehran is open 24 hours a day and requires a varying number of cashiers to meet service demands during each hour. You are given 24 integers \(R(0), R(1), \dots, R(23)\) where \(R(i)\) indicates the minimum number of cashiers needed from hour \(i\) to \(i+1\) (with \(R(0)\) representing midnight to 1:00 A.M., etc.).

There are \(N\) qualified applicants. Each applicant works a continuous shift of exactly 8 hours starting at a fixed hour \(t\) (where \(0 \le t \le 23\)) if hired. If an applicant starting at \(t\) is hired, they work from \(t\) o'clock sharp for 8 consecutive hours (covering hours \(t, t+1, \dots, t+7\), with hours taken modulo 24).

Your task is to select a subset of the applicants (by hiring some of them) so that for every hour \(i\) the total number of working cashiers covering that hour is at least \(R(i)\). Note that you may hire more cashiers than required for any particular hour, but your goal is to minimize the total number hired. Also, an applicant can only be hired at his/her specific starting hour and there is a limited number of applicants available for each starting time.

Input/Output Format:

The problem input and output details are given below.

inputFormat

The input consists of:

  1. A single line with 24 non‐negative integers representing \(R(0), R(1), \dots, R(23)\), separated by spaces.
  2. A line with a non‐negative integer \(N\), the number of qualified applicants.
  3. A line with \(N\) non‐negative integers where each integer represents the starting hour \(t_i\) (with \(0 \le t_i \le 23\)) for the \(i\)th applicant.

You can assume that all numbers are integers and that a solution exists unless stated otherwise.

outputFormat

Output a single integer representing the minimum number of cashiers that need to be hired so that every hour \(i\) is covered by at least \(R(i)\) cashiers.

sample

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0
0