#C1546. Lecture Scheduling Problem

    ID: 44763 Type: Default 1000ms 256MiB

Lecture Scheduling Problem

Lecture Scheduling Problem

You are given a set of n lectures and m lecture halls. Each lecture i requires a capacity c_i and each hall j has a capacity h_j. Additionally, there are p scheduling restrictions. Each restriction is provided as a triple (type, x, y), where type can be 0 or 1. For a restriction of type 0, lectures x and y must not be scheduled in the same hall at the same time (time conflict). For a restriction of type 1, the lectures x and y (which might be given by the same lecturer) also cannot share the same hall.

The scheduling must satisfy the following conditions:

  • For each lecture i, it can only be assigned to a hall j if c_i \leq h_j (written in \(\LaTeX\) as \( c_i \leq h_j \)).
  • For every restriction between lectures, the two lectures must not be assigned the same hall.

Determine whether it is possible to assign each lecture to a hall while satisfying all capacity constraints and scheduling restrictions. Output YES if a valid assignment exists, otherwise output NO.

inputFormat

The input is read from standard input (stdin) in the following format:

<n>
<c1 c2 ... cn>
<m>
<h1 h2 ... hm>
<p>
<type1 x1 y1>
<type2 x2 y2>
...
<typep xp yp>

where:

  • n is the number of lectures.
  • c1, c2, ..., cn are the capacities required for each lecture.
  • m is the number of lecture halls.
  • h1, h2, ..., hm represent the capacities of each hall.
  • p is the number of restrictions.
  • Each of the next p lines contains three integers: type, x, and y, representing a restriction. Note that x and y are 1-indexed lecture numbers.

outputFormat

Output a single line to standard output (stdout) containing YES if a valid scheduling is possible, or NO if it is not.

## sample
4
100 150 200 180
3
150 200 300
5
0 1 2
0 3 4
1 1 3
1 2 3
1 3 4
YES