# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1164288 | cjtsai | Fire (BOI24_fire) | Pypy 3 | 0 ms | 0 KiB |
# Preprocess intervals:
for each interval [s, e]:
if s <= e:
add interval [s, e]
add interval [s + M, e + M]
else: # s > e, wrap-around
add interval [s, e + M]
ans = infinity
# Try every starting point T in the range [0, M)
for each candidate T that is a valid start:
current_end = T
count = 0
while current_end < T + M:
# among all intervals with start <= current_end, choose one with max end
best = max( end for interval if interval.start <= current_end )
if best <= current_end:
break # gap found, cannot cover
current_end = best
count += 1
if current_end >= T + M:
ans = min(ans, count)
if ans is infinity:
print(-1)
else:
print(ans)