Mission control operates a deep-space probe that delivers telemetry payloads back to Earth through a chain of relay satellites. For a single transmission, the payload passes through k relay hops in sequence, and hop j adds delay_j milliseconds before forwarding the payload onward; the total time to deliver the payload is the sum of all its hops' delays. Every transmission mission control attempts is held to the same fixed communication window of L milliseconds, checked independently of how the hops are performing: if the total hop delay is at most L, the payload arrives and its value is recorded; if the total delay would exceed L, the transmission is abandoned and marked as lost, no matter how close it came to making it.
Given q transmissions, each with its own payload value and its own chain of hop delays, report the outcome of every transmission in order.
The first line contains two integers q L.
Each transmission is then described by two lines:
k v, the number of relay hops and the payload value;k integers delay_1 ... delay_k (this line has no numbers on it when k is 0).Print q lines. For the i-th transmission, print the payload value v if the sum of its hop delays is at most L; otherwise print the single word ABORTED.
k over all transmissions is at most 2*10^5Example 1
Input
2 100 3 7 30 40 20 2 99 60 50
Expected
7 ABORTED
Explanation
The shared window is L=100ms. Transmission 1 has payload 7 and hop delays 30+40+20=90ms, which is at most 100, so it succeeds and prints 7. Transmission 2 has payload 99 and hop delays 60+50=110ms, which exceeds 100, so it is lost and prints ABORTED.
Example 2
Input
1 50 0 5
Expected
5
Explanation
There is a single transmission with 0 relay hops and payload value 5. With no hops, the total delay is 0ms, which is at most the window L=50, so it succeeds and prints 5.
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 →