Tap here to switch tabs
Problem
Submissions

Problem: Mark Elements on Array by Performing Queries

Try to solve the Mark Elements on Array by Performing Queries problem.

Statement

You are given an array nums of size n containing positive integers and an array queries of size m, where queries[i] = [index_i, k_i].

Initially, all elements in nums are unmarked. You need to process each query sequentially in the following manner:

  1. Mark the element located at index index_i if it is not already marked.

  2. Mark up to k_i unmarked elements that have the smallest values. If there is a tie in values, choose the elements with the smallest indices. If there are fewer than k_i unmarked elements remaining, mark all of them.

  3. Calculate the sum of all unmarked elements in nums after completing the steps above.

Return an array of integers representing the sum of unmarked elements after each query.

Constraints:

  • n ==== nums.length

  • m ==== queries.length

  • 1≤m≤n≤1051 \leq m \leq n \leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • queries[i].length ==2== 2

  • 0≤0 \leq index_i, k_i ≤n−1\leq n - 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Mark Elements on Array by Performing Queries

Try to solve the Mark Elements on Array by Performing Queries problem.

Statement

You are given an array nums of size n containing positive integers and an array queries of size m, where queries[i] = [index_i, k_i].

Initially, all elements in nums are unmarked. You need to process each query sequentially in the following manner:

  1. Mark the element located at index index_i if it is not already marked.

  2. Mark up to k_i unmarked elements that have the smallest values. If there is a tie in values, choose the elements with the smallest indices. If there are fewer than k_i unmarked elements remaining, mark all of them.

  3. Calculate the sum of all unmarked elements in nums after completing the steps above.

Return an array of integers representing the sum of unmarked elements after each query.

Constraints:

  • n ==== nums.length

  • m ==== queries.length

  • 1≤m≤n≤1051 \leq m \leq n \leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • queries[i].length ==2== 2

  • 0≤0 \leq index_i, k_i ≤n−1\leq n - 1