cswork / OA打开练习工作台

Goldman SachsOA #21

Longest Subarray

估计中等可在线判题

考点(AI 标注)双指针滑窗前缀和区间

Given an array of positive integers, find the length of the longest contiguous subarray whose sum does not exceed k.

输入格式

The first line contains n k (1≤n≤100000, 1≤k≤10^9); the second line contains n positive integers a[i] (1..1000).

输出格式

Output the maximum length of a subarray with sum ≤k; output 0 if no non-empty subarray qualifies.

样例 1

输入:

3 4
1 2 3

输出:

2

样例 2

输入:

4 4
3 1 2 3

输出:

2

样例 3

输入:

1 6
7

输出:

0