3049. Earliest Second to Mark Indices II
You are given two 1-indexed integer arrays,
nums
and,changeIndices
, having lengthsn
andm
, respectively.Initially, all indices in
nums
are unmarked. Your task is to mark all indices innums
.In each second,
s
, in order from1
tom
(inclusive), you can perform one of the following operations:
- Choose an index
i
in the range[1, n]
and decrementnums[i]
by1
.- Set
nums[changeIndices[s]]
to any non-negative value.- Choose an index
i
in the range[1, n]
, wherenums[i]
is equal to0
, and mark indexi
.- Do nothing.
Return an integer denoting the earliest second in the range
[1, m]
when all indices innums
can be marked by choosing operations optimally, or-1
if it is impossible.
c++
1 |
|