← 返回 bytedance 的题目列表Maximize Video Watching Time
类型:online_judge
Select a subset of videos from a given list such that the sum of durations of any two consecutive selected videos does not exceed the user's attention span, and maximize the total viewing time. Given an integer array durations where each element is the duration of a video and an integer maxAttention representing the user's attention span, write a function to output the maximum total viewing time.
Input
An integer array durations, where each element represents the duration of a video.
An integer maxAttention, the user's attention span.
Output
An integer, the maximum total viewing time possible.
Example
For input durations = [10, 15, 20, 5] and maxAttention = 30,
The output is 35. We can select video 1 (15 minutes) and video 3 (20 minutes), resulting in a total viewing time of 35 minutes.
Constraints
1 <= durations.length <= 10^4
1 <= durations[i] <= 10^4
1 <= maxAttention <= 10^4
Example
Input
[10, 15, 20, 5]\n30