← 返回 bytedance 的题目列表Subset of Videos with Attention Span Constraint
类型:online_judge
Given a collection of video durations, select a subset such that the sum of the durations of any two consecutively selected videos does not exceed a specified attention span, and maximize the total viewing duration. Implement an algorithm to solve this problem and provide test cases.
Input Format:
The first line contains two integers n and T, representing the number of videos and the attention span.
The second line contains n integers, representing the duration of each video.
Output Format:
Output the maximum viewing duration.
Input Constraints:
1 <= n <= 1000
1 <= video duration <= 1000
Test Cases:
Input:
5 10
1 2 3 4 5
Output:
9
Input:
3 5
5 5 5
Output:
5
Note:
Remember to handle edge cases, such as if no videos meet the criteria, output 0.
Example
Input
5 10
1 2 3 4 5