Tap here to switch tabs
Problem
Submissions

Problem: K Items With the Maximum Sum

med
30 min
Try to solve the K Items With the Maximum Sum problem.

Statement

You are given four integers numOnes, numZeros, numNegOnes, and k.

There is a bag containing items with numbers written on them:

  • numOnes items with the number 11

  • numZeros items with the number 00

  • numNegOnes items with the number −1-1

Your task is to select exactly k items from the bag such that the sum of their values is maximized. Return the maximum possible sum.

Constraints:

  • 0≤0 \leq numOnes, numZeros, numNegOnes ≤50\leq 50

  • 0≤0 \leq k ≤\leq numOnes ++ numZeros ++ numNegOnes

⋮
Tap here to switch tabs
Problem
Submissions

Problem: K Items With the Maximum Sum

med
30 min
Try to solve the K Items With the Maximum Sum problem.

Statement

You are given four integers numOnes, numZeros, numNegOnes, and k.

There is a bag containing items with numbers written on them:

  • numOnes items with the number 11

  • numZeros items with the number 00

  • numNegOnes items with the number −1-1

Your task is to select exactly k items from the bag such that the sum of their values is maximized. Return the maximum possible sum.

Constraints:

  • 0≤0 \leq numOnes, numZeros, numNegOnes ≤50\leq 50

  • 0≤0 \leq k ≤\leq numOnes ++ numZeros ++ numNegOnes