#K15331. Taco Production Scheduling

    ID: 24333 Type: Default 1000ms 256MiB

Taco Production Scheduling

Taco Production Scheduling

In this problem, you are given a set of production schedules for a taco workshop. There are N types of widgets (taco ingredients) and each requires a certain amount of time to prepare. The company operates M production lines, where each line has a schedule represented as a sequence of widget type indices. The time required to process a widget of type i is given by T[i]. For each query, you are provided with an available time and you must determine if the entire production schedule can be completed within that time.

The total processing time can be expressed in LaTeX as follows:

\(\text{TotalTime} = \sum_{k=1}^{M} \sum_{j=1}^{L_k} T[w_{kj}]\),

where \(L_k\) is the number of tasks in the schedule for the k-th production line and \(w_{kj}\) is the widget (ingredient) type in the j-th position of that schedule. If the available time for a query is greater than or equal to \(\text{TotalTime}\), then it is possible to finish the schedules (output "YES"), otherwise output "NO".

inputFormat

The input is given via standard input (stdin) in the following format:

N
T1 T2 ... TN
M
L1 w11 w12 ... w1L1
L2 w21 w22 ... w2L2
... 
LM wM1 wM2 ... wMLM
Q
A1 A2 ... AQ

Where:

  • N is the number of widget types.
  • T1, T2, ..., TN are the time units required for each widget type.
  • M is the number of production lines.
  • Each of the next M lines starts with an integer L (the number of tasks in that schedule) followed by L integers indicating the widget type indices for that schedule.
  • Q is the number of queries.
  • The last line contains Q integers, each representing an available time for the corresponding query.
  • outputFormat

    For each query, print on a new line YES if the total required time to complete all schedules is less than or equal to the available time, otherwise print NO.

    The output should be printed to standard output (stdout).

    ## sample
    3
    5 10 15
    2
    4 1 2 3 1
    3 2 3 2
    2
    60 100
    
    NO
    

    YES

    </p>