An orchard's automatic irrigation controller waters three zones — Zone A, Zone B, and Zone C — one at a time, always in that fixed order, forever repeating. Starting at time 0, the controller opens Zone A's valve for exactly A seconds, then closes it and opens Zone B's valve for exactly B seconds, then closes it and opens Zone C's valve for exactly C seconds, and then the whole A + B + C-second cycle starts over again from Zone A. Only one zone's valve is ever open at a time.
Given the three durations and a list of query timestamps, determine which zone's valve is open at each queried timestamp.
A, B, and C — the number of seconds Zone A, Zone B, and Zone C each water for during one cycle.q — the number of queries.q integers t_1 ... t_q, the query timestamps in seconds, measured from the moment the controller first opened Zone A's valve at time 0.Print q lines. The i-th line must contain a single character — A, B, or C — naming the zone whose valve is open at timestamp t_i.
Example 1
Input
3 2 4 5 0 2 4 8 9
Expected
A A B C A
Explanation
The cycle is 3+2+4=9 seconds long: Zone A is open during [0,3), Zone B during [3,5), and Zone C during [5,9). At t=0 and t=2, Zone A is open. At t=4, Zone B is open. At t=8, Zone C is open. At t=9, a new cycle has just begun (9 mod 9 = 0), so Zone A is open again.
Example 2
Input
1 1 1 3 1000000000000 1000000000001 1000000000002
Expected
B C A
Explanation
Each zone waters for exactly 1 second, so the cycle is 3 seconds long: Zone A during [0,1), Zone B during [1,2), Zone C during [2,3). Since 1,000,000,000,000 mod 3 = 1, that timestamp falls in Zone B's window. The next timestamp, 1,000,000,000,001, is 2 mod 3, falling in Zone C's window. The one after that, 1,000,000,000,002, is a multiple of 3 (0 mod 3), so it falls at the very start of Zone A's window again.
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 →