#K44447. Synchronizing Light Schedules
Synchronizing Light Schedules
Synchronizing Light Schedules
You are given the schedules of l lights. Each light has a series of on/off intervals specified by a triple (start_time, end_time, state), where state is either 0 (off) or 1 (on). The intervals for each light must not overlap (although they may touch at the boundaries). Formally, for each light and for any two consecutive intervals when sorted by start time, if the first interval is [s, e] and the second is [s', e'], then it must hold that \( e \leq s' \). If any light has overlapping intervals, the schedule is considered invalid.
Your task is to determine whether all lights have valid, non-overlapping schedules so that they can be synchronized. Output possible
if the schedule for every light is valid, otherwise output impossible
.
inputFormat
The input is given through standard input (stdin) in the following format:
l k1 s11 e11 state11 s12 e12 state12 ... s1k1 e1k1 state1k1 k2 s21 e21 state21 ... s2k2 e2k2 state2k2 ... kl sl1 el1 statel1 ... slkl elkl statelkl
Here, l is the number of lights. For each light, the first line contains an integer k representing the number of intervals for that light. Then k lines follow, each containing three integers: the start time, the end time, and the state. An empty schedule is indicated by k = 0.
outputFormat
Print a single line to standard output (stdout) containing either possible
if all schedules are valid (i.e. no overlapping intervals within any light) or impossible
if there is an overlap in any light's schedule.
1
1
0 5 1
possible