Problem 3049 · Hard

Earliest Second to Mark Indices II

Each second you may decrement any entry, reset the entry named by changeIndices for that second to any non-negative value, mark any index whose entry is 0, or do nothing. Find the earliest second by which every index can be marked, or -1 if that never happens.

Open the interactive visualisation