#K48542. Minimum Length Segment Exceeding Threshold

    ID: 28443 Type: Default 1000ms 256MiB

Minimum Length Segment Exceeding Threshold

Minimum Length Segment Exceeding Threshold

You are given a circular array of n checkpoints. Each checkpoint has a difficulty level. Your task is to determine the minimum length L of a contiguous segment (which may wrap around) such that the sum of the difficulties in that segment is strictly greater than a given threshold T. In other words, find the smallest L for which there exists an index i such that

$$\sum_{j=i}^{i+L-1} d_j > T,$$

where the indices are considered modulo n. If no such segment exists, output -1.

Note: The input is read from stdin and output should be printed to stdout.

inputFormat

The first line of input contains two integers n and T, where n is the number of checkpoints and T is the difficulty threshold.

The second line contains n space-separated integers indicating the difficulty level of each checkpoint.

Example:

5 8
2 3 6 1 4

outputFormat

Output a single integer representing the minimum segment length whose total difficulty exceeds T. If no segment satisfies the condition, output -1.

Example:

2
## sample
5 8
2 3 6 1 4
2

</p>