Finding the Mysterious Subarray

Xem dạng PDF

Gửi bài giải

Điểm: 1,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: stdin
Output: stdout

Nguồn bài:
Châu Nhật Tăng
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

In a distant land, there is a library containing thousands of valuable books. Every day, the librarian must arrange the books on the shelves, but there is a challenge: the total weight of the books on a shelf must not exceed a certain limit, or the shelf will collapse.

You are tasked with finding the longest consecutive sequence of books whose total weight does not exceed the allowed limit. This sequence will help the librarian organize the library most efficiently.

Given an array of ~n~ integers, where each element represents the weight of a book, you need to find the longest consecutive subarray whose total weight does not exceed ~t~. The length of this longest subarray is the result you need to determine.

Input

  • The first line contains two integers ~n, t~ ~(1 ≤ n ≤ 10^5, 1 ≤ t ≤ 10^{15})~ — the number of books and the maximum allowed total weight on a shelf.
  • The second line contains ~n~ positive integers ~a_1, a_2, ..., a_n~ ~(1 ≤ a_i ≤ 10^{9})~ — the weights of the books in order.

Output

  • Print a single integer — the maximum length of a consecutive subarray whose total weight does not exceed ~t~.

Example Input

5 10  
1 2 3 4 5  

Example Output

4  

Explanation:

  • The librarian can choose the following consecutive subarrays to place on the shelf:

    • {1, 2, 3, 4} with a total weight of ~10~ (length ~4~)
    • {2, 3, 4} with a total weight of ~9~ (length ~3~)
    • {3, 4} with a total weight of ~7~ (length ~2~)
    • {5} with a total weight of ~5~ (length ~1~)
  • The longest subarray with a total weight not exceeding ~10~ is {1, 2, 3, 4}, with a length of ~4~.


Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.