#C876. Longest Contiguous Subsequence with Sum Constraint
Longest Contiguous Subsequence with Sum Constraint
Longest Contiguous Subsequence with Sum Constraint
You are given a sequence of N tasks, each with a certain difficulty level, and an integer T representing the maximum allowed total difficulty. Your goal is to find the length of the longest contiguous subsequence of tasks such that the sum of their difficulty levels does not exceed T.
Problem Details:
- The first line of the input contains two integers, N and T, where N is the number of tasks and T is the difficulty tolerance.
- The second line contains N integers representing the difficulty levels of the tasks.
Your task is to output a single integer representing the maximum number of consecutive tasks whose total difficulty is less than or equal to T.
Example:
For instance, if the input is:
6 8 1 2 3 4 5 1
Then the longest contiguous subsequence with a sum not exceeding 8 is of length 3, so the output should be:
3
inputFormat
The input is given via standard input and consists of two lines:
- The first line contains two integers N and T separated by a space.
- The second line contains N space-separated integers representing the difficulty levels of the tasks.
outputFormat
Output a single integer representing the length of the longest contiguous subsequence of tasks whose total difficulty does not exceed T.
## sample6 8
1 2 3 4 5 1
3