Reel Changeover Booth
MediumOnline Assessment
Work out when a cinema's pre-show reels reach the screen and how much black screen the audience gets while the projectionist changes over.
A pre-show program is a list of short reels played on two projectors, A and B, alternating: reel 0 on A, reel 1 on B, reel 2 on A again, and so on. All times are in seconds from the moment reel 0's motor starts (time 0).
lengths[i] is how long reel i runs, from its motor start until the film runs out. Reel i carries two cue marks, cues[i] = [motor, change] with 0 < change < motor < lengths[i]: the motor cue appears motor seconds before its film runs out, and the changeover cue appears change seconds before it runs out. When reel i shows a motor cue the projectionist starts the motor of reel i + 1. Reel i + 1's picture then reaches the screen motor - change seconds after its motor starts, and at that moment reel i's picture leaves the screen.
Reels 0 and 1 are threaded before the show. Any later reel i must be threaded onto the projector that played reel i - 2, which takes lace[i] seconds (lace[0] and lace[1] are unused). Threading starts at the later of two moments: when reel i - 2 runs out, and when reel i - 1's picture reaches the screen (the projectionist is busy until then). If reel i is not yet threaded when reel i - 1 shows its motor cue, its motor starts the moment threading finishes; the extra wait is black screen.
Input: lengths, cues, lace, equal-length lists (cues holds [motor, change] pairs).
Output: [finish, black, late]: the moment the last reel's picture leaves the screen (its film runs out minus its own changeover cue), the total seconds of black screen across all changeovers, and the number of changeovers with any black screen.
Example 1
- Input:
- [[100,100,100],[[10,6],[10,6],[10,6]],[0,0,40]]
- Output:
- [274,0,0]
- Explanation
- Reel 0 runs out at 100. Reel 1 starts at its motor cue, 100 - 10 = 90, runs out at 190, and reaches the screen at 90 + (10 - 6) = 94. Reel 2 is threaded after the later of 100 (reel 0 running out) and 94, so at 100 + 40 = 140, well before reel 1's motor cue at 190 - 10 = 180. It starts at 180 and runs out at 280; the last picture leaves the screen at 280 - 6 = 274. No black screen.
Example 2
- Input:
- [[100,90,80,70],[[10,6],[12,5],[8,3],[9,4]],[0,0,100,80]]
- Output:
- [353,47,2]
- Explanation
- Reel 1 starts at 90, reaches the screen at 94 and runs out at 180. Reel 2 cannot be threaded until 100, and takes 100 seconds: ready at 200, but its motor cue was at 180 - 12 = 168, so it starts 32 seconds late (32 seconds of black). It reaches the screen at 200 + (12 - 5) = 207 and runs out at 280. Reel 3 starts threading at the later of 180 and 207, so at 207, and is ready at 287; the motor cue was at 280 - 8 = 272, so another 15 seconds of black. It runs out at 287 + 70 = 357; finish 357 - 4 = 353, black 47, two late changeovers.
Example 3
- Input:
- [[60],[[20,5]],[0]]
- Output:
- [55,0,0]
- Explanation
- A single reel has no changeovers: it runs from 0 to 60 and its picture leaves the screen at 60 - 5 = 55.
Constraints
- 1 ≤ lengths.length = cues.length = lace.length ≤ 200
- 1 ≤ lace[i] ≤ 600; 30 ≤ lengths[i] ≤ 600
- 0 < cues[i][1] < cues[i][0] < lengths[i]