I could not solve this problem during the contest, but after some struggle, I managed to pass the tests.
2 * k
minutes.amax <= t <= amax + k
.
t < amax
: the last room's light are off.t > amax + 2k
: repeating the same pattern, and they
are not the earliest moment.from collections import defaultdict
for _ in range(int(input())):
n, k = map(int, input().split())
a: list[int] = list(map(int, input().split()))
amax: int = max(a)
amod: list[int] = [x + (amax - x) // (2 * k) * (2 * k) for x in a]
amod = [x + 2 * k if amax - x > k else x for x in amod]
amodmax = max(amod)
amodmin = min(amod)
if amodmax - amodmin < k:
print(amodmax)
else:
print(-1)
Ketone 5 mg/dl
Salad 30g Protein shake 10g
Total carbohydrate 40 g
MUST:
TODO: