Meridian Labs runs an automated bench that calibrates all n of its environmental sensors at once: at time zero it launches n independent calibration jobs in parallel, one per sensor, with no queueing or staggering. Job i is known in advance to take exactly t_i seconds, after which it settles in one of two ways: it either succeeds and reports a calibrated reading x_i, or it fails and reports a fault code x_i instead. The bench's controller watches every job at once. If every job eventually succeeds, the controller waits for the slowest of them and then publishes all n readings, listed in the original sensor order (1 through n), regardless of which job actually finished first. But the instant any job fails, the controller abandons the whole batch and reports only the single failing job that settles earliest — the failure with the smallest t_i, breaking ties by the smaller sensor index — discarding the outcome of every other job entirely, whether it succeeded, is still pending, or fails even later.
n, the number of sensors.n lines contains three space-separated integers t_i s_i x_i: t_i is job i's duration in seconds, s_i is 1 if job i succeeds or 0 if it fails, and x_i is the calibrated reading (when s_i = 1) or fault code (when s_i = 0).OK on the first line, then on the second line print the n readings x_1 x_2 ... x_n in original sensor order, space-separated.FAIL on the first line, then on the second line print two space-separated integers: the 1-indexed sensor number of the earliest-settling failing job, and that job's fault code.1 <= n <= 1000001 <= t_i <= 1000000000s_i is 0 or 1-1000000000 <= x_i <= 1000000000Example 1
Input
3 5 1 10 3 1 20 8 1 30
Expected
OK 10 20 30
Explanation
All three jobs succeed, so the controller waits for the slowest one (job 3 at t=8s) and then publishes every reading in original sensor order — 10, 20, 30 — printing `OK` followed by `10 20 30`.
Example 2
Input
3 5 1 10 3 0 -7 8 0 -9
Expected
FAIL 2 -7
Explanation
Job 2 fails at t=3s and job 3 fails at t=8s; job 1 succeeds at t=5s but that outcome is irrelevant once any job fails. Between the two failures, job 2 settles earliest (3 < 8), so the controller reports `FAIL` and then `2 -7`, discarding job 1's success and job 3's later failure entirely.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →