Reducing Dishes
Real-world version: Running Order For The Demo ReelThe statement here is our own: the same inputs, outputs and technique.
A showcase reel is cut together from a pile of clips. Clip i has been given a rating ratings[i] by the review panel, and a rating may be negative when the panel disliked the clip.
You choose which clips go into the reel and what order they play in. Any number of clips may be left out, including all of them. A clip that ends up in position p of the finished reel scores p * rating, where positions are numbered 1, 2, 3, ... over the clips that were actually included, so leaving a clip out shifts everything after it one position earlier. The reel's value is the sum of the scores of its clips, and an empty reel is worth 0.
Return the largest value a reel cut from these clips can have.
Examples
Example 1
- Input
- ratings = [-4, 1, 2]
- Output
- 5
Leave the clip rated -4 out and play the other two as 1 then 2. That reel scores 1 * 1 + 2 * 2 = 5.
Example 2
- Input
- ratings = [-1, 5, 6]
- Output
- 27
Include all three clips in the order -1, 5, 6. The scores are 1 * (-1), 2 * 5 and 3 * 6, which add up to 27.
Example 3
- Input
- ratings = [-7, -2, -3]
- Output
- 0
Every clip is rated below zero. Leaving all of them out gives an empty reel, worth 0.
Constraints
- n == ratings.length
- 1 <= n <= 500
- -1000 <= ratings[i] <= 1000
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def max_reel_value(ratings: list[int]) -> int:public int maxReelValue(int[] ratings)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 16 test cases: 16 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Non-overlapping IntervalsReal-world version: Drop the Clashing Kiln RunsMedium
- Minimize the Maximum Difference of PairsReal-world version: Pairing Gears by Closest Tooth CountMedium
- Path Existence Queries in a Graph IIReal-world version: Relay Hops Across The Field NetworkHard
- Assign CookiesReal-world version: Scratch Space HandoutEasy