Tap here to switch tabs
Problem
Submissions

Problem: Earliest Second to Mark Indices II

Earliest Second to Mark Indices II gives nums and changeIndices. Find the earliest second when every index can be marked using decrements, resets to zero, and marking indices at zero, or return -1.

Statement

You are given two 11 indexed integer arrays, nums of length n and changeIndices of length m.

Initially, all indices in nums are unmarked.

At each second s from 11 to m, you can perform one of the following operations:

  • Choose an index i such that 1≤1 \le i ≤\le n, and decrement nums[i] by 11.

  • Set nums[changeIndices[s]] to 00.

  • Choose an index i such that 1≤1 \le i ≤\le n and nums[i] is equal to 00, and mark index i.

  • Do nothing.

Return an integer representing the earliest second in the range [1,m][1, m] at which all indices in nums can be marked, or −1-1 if it is impossible to mark all indices.

Constraints:

  • 1≤1 \le n ==== nums.length ≤5000\le 5000

  • 0≤0 \le nums[i] ≤109\le 10^9

  • 1≤1 \le m ==== changeIndices.length ≤5000\le 5000

  • 1≤1 \le changeIndices[i] ≤\le n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Earliest Second to Mark Indices II

Earliest Second to Mark Indices II gives nums and changeIndices. Find the earliest second when every index can be marked using decrements, resets to zero, and marking indices at zero, or return -1.

Statement

You are given two 11 indexed integer arrays, nums of length n and changeIndices of length m.

Initially, all indices in nums are unmarked.

At each second s from 11 to m, you can perform one of the following operations:

  • Choose an index i such that 1≤1 \le i ≤\le n, and decrement nums[i] by 11.

  • Set nums[changeIndices[s]] to 00.

  • Choose an index i such that 1≤1 \le i ≤\le n and nums[i] is equal to 00, and mark index i.

  • Do nothing.

Return an integer representing the earliest second in the range [1,m][1, m] at which all indices in nums can be marked, or −1-1 if it is impossible to mark all indices.

Constraints:

  • 1≤1 \le n ==== nums.length ≤5000\le 5000

  • 0≤0 \le nums[i] ≤109\le 10^9

  • 1≤1 \le m ==== changeIndices.length ≤5000\le 5000

  • 1≤1 \le changeIndices[i] ≤\le n