Tap here to switch tabs
Problem
Submissions

Problem: Earliest Second to Mark Indices I

med
30 min
Try to solve the Earliest Second to Mark Indices I problem.

Statement

You are given two 11 indexed integer arrays, nums of length nn and changeIndices of length mm.

Initially, all indices from 11 to nn are unmarked. In each second, starting from second 11 up to second mm, you can perform exactly one of the following actions:

  • Choose an index ii such that 1≤i≤n1 \leq i \leq n and decrease nums[i] by 11.

  • Mark index changeIndices[s] if nums[changeIndices[s]] equals 00.

  • Do nothing.

Return the earliest second at which all indices from 11 to nn can be marked. If it is impossible to mark all indices within mm seconds, return −1-1.

Constraints:

  • 1≤n==1 \leq n == nums.length ≤2000\leq 2000

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

  • 1≤m==1 \leq m == changeIndices.length ≤2000\leq 2000

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

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Earliest Second to Mark Indices I

med
30 min
Try to solve the Earliest Second to Mark Indices I problem.

Statement

You are given two 11 indexed integer arrays, nums of length nn and changeIndices of length mm.

Initially, all indices from 11 to nn are unmarked. In each second, starting from second 11 up to second mm, you can perform exactly one of the following actions:

  • Choose an index ii such that 1≤i≤n1 \leq i \leq n and decrease nums[i] by 11.

  • Mark index changeIndices[s] if nums[changeIndices[s]] equals 00.

  • Do nothing.

Return the earliest second at which all indices from 11 to nn can be marked. If it is impossible to mark all indices within mm seconds, return −1-1.

Constraints:

  • 1≤n==1 \leq n == nums.length ≤2000\leq 2000

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

  • 1≤m==1 \leq m == changeIndices.length ≤2000\leq 2000

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