#C537. Longest Consecutive Coin Sequence

    ID: 49011 Type: Default 1000ms 256MiB

Longest Consecutive Coin Sequence

Longest Consecutive Coin Sequence

You are given an array of N coins and an integer K. The task is to find the length of the longest contiguous subarray (i.e. a sequence of consecutive coins) such that the sum of the coins in that subarray does not exceed K.

Formally, given an array coins of length N, you need to determine the maximum integer L for which there exists an index i (with 0 \le i \le N - L) satisfying

$$\sum_{j=i}^{i+L-1} coins[j] \le K.$$

Input/Output Format: The solution must read from standard input and write to standard output.

Example: For N = 5, K = 10 and coins = [2, 1, 3, 4, 5], one valid longest sequence is [2, 1, 3, 4] with a sum of 10, hence the output is 4.

inputFormat

The first line contains two space-separated integers N and K. The second line contains N space-separated integers representing the coin values.

outputFormat

Output a single integer, the length of the longest contiguous subarray whose sum does not exceed K.## sample

5 10
2 1 3 4 5
4

</p>