Tap here to switch tabs
Problem
Submissions

Problem: Largest Values From Labels

med
30 min
Try to solve the Largest Values From Labels problem.

Statement

You are given two integer arrays values and labels of length nn, and two integers numWanted and useLimit. The value and label of the item at index ii are values[i] and labels[i], respectively.

Find the maximum possible sum of values from a subset of items such that:

  • The subset contains at most numWanted items.

  • For each label, the subset contains at most useLimit items with that label.

Return the maximum sum that can be obtained.

Constraints:

  • n == values.length == labels.length

  • 1≤n≤2⋅1041 \le n \le 2 \cdot 10^4

  • 0≤0 \le values[i], labels[i] ≤2⋅104\le 2 \cdot 10^4

  • 1≤1 \le numWanted, useLimit ≤n\le n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Largest Values From Labels

med
30 min
Try to solve the Largest Values From Labels problem.

Statement

You are given two integer arrays values and labels of length nn, and two integers numWanted and useLimit. The value and label of the item at index ii are values[i] and labels[i], respectively.

Find the maximum possible sum of values from a subset of items such that:

  • The subset contains at most numWanted items.

  • For each label, the subset contains at most useLimit items with that label.

Return the maximum sum that can be obtained.

Constraints:

  • n == values.length == labels.length

  • 1≤n≤2⋅1041 \le n \le 2 \cdot 10^4

  • 0≤0 \le values[i], labels[i] ≤2⋅104\le 2 \cdot 10^4

  • 1≤1 \le numWanted, useLimit ≤n\le n