Skip to the code
+10 XP

#520 Sell Timeline Clips for the Most

easy

A stock video site buys clips by length. prices[k - 1] is what it pays for one clip that is exactly k seconds long, for k from 1 to prices.length. You have a timeline length seconds long and can cut it into whole-second clips of any allowed lengths, using each length as often as you like.

Write bestClipSale(prices, length) that returns the most money you can get for the whole timeline.

Example 1

Input: prices = [2,5,7,8], length = 4
Output: 10

Two 2-second clips: 5 + 5. One 4-second clip pays only 8.

Example 2

Input: prices = [3], length = 5
Output: 15

Only 1-second clips are allowed: 5 × 3.

Constraints

  • 1 <= prices.length <= 100
  • 1 <= length <= 1000
  • 0 <= prices[i] <= 10000
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).