301480: CF279B. Books

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Books

题意翻译

你有 $n$ 本书,读第 $i$ 本书需要 $a_i$ 分钟,你现在有 $m$ 分钟 你读书的方式是这样的:找出任意一个数 $x$,并按编号从小到大的顺序读第 $x \sim n$ 本 如果你读完了第 $n$ 本,那么读书结束 如果你准备要读第 $i$ 本书,但是剩下的时间小于 $a_i$(也就是读不完这本书):那么你就**不可以开始读**这本书了,并且读书结束 换句话说,如果你读一本书,就必须要读完,否则就不能读 求最多能读多少本书 ### 输入格式 第一行两个整数 $n,m$,分别表示书的数量和限定时间 第二行 $n$ 个整数 $a_1 \sim a_n$,表示读每本书的所耗时间 ### 输出格式 一行一个整数,表示最多能读的书的数量 #### 说明与提示 $1 \le n \le 10^5$ $1 \le m \le 10^9$ $1 \le a_i \le 10^4$ 感谢 @[_Wolverine](https://www.luogu.com.cn/user/120362) 提供的翻译

题目描述

When Valera has got some free time, he goes to the library to read some books. Today he's got $ t $ free minutes to read. That's why Valera took $ n $ books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to $ n $ . Valera needs $ a_{i} $ minutes to read the $ i $ -th book. Valera decided to choose an arbitrary book with number $ i $ and read the books one by one, starting from this book. In other words, he will first read book number $ i $ , then book number $ i+1 $ , then book number $ i+2 $ and so on. He continues the process until he either runs out of the free time or finishes reading the $ n $ -th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it. Print the maximum number of books Valera can read.

输入输出格式

输入格式


The first line contains two integers $ n $ and $ t $ $ (1<=n<=10^{5}; 1<=t<=10^{9}) $ — the number of books and the number of free minutes Valera's got. The second line contains a sequence of $ n $ integers $ a_{1},a_{2},...,a_{n} $ $ (1<=a_{i}<=10^{4}) $ , where number $ a_{i} $ shows the number of minutes that the boy needs to read the $ i $ -th book.

输出格式


Print a single integer — the maximum number of books Valera can read.

输入输出样例

输入样例 #1

4 5
3 1 2 1

输出样例 #1

3

输入样例 #2

3 3
2 2 3

输出样例 #2

1

Input

题意翻译

你有 $n$ 本书,读第 $i$ 本书需要 $a_i$ 分钟,你现在有 $m$ 分钟 你读书的方式是这样的:找出任意一个数 $x$,并按编号从小到大的顺序读第 $x \sim n$ 本 如果你读完了第 $n$ 本,那么读书结束 如果你准备要读第 $i$ 本书,但是剩下的时间小于 $a_i$(也就是读不完这本书):那么你就**不可以开始读**这本书了,并且读书结束 换句话说,如果你读一本书,就必须要读完,否则就不能读 求最多能读多少本书 ### 输入格式 第一行两个整数 $n,m$,分别表示书的数量和限定时间 第二行 $n$ 个整数 $a_1 \sim a_n$,表示读每本书的所耗时间 ### 输出格式 一行一个整数,表示最多能读的书的数量 #### 说明与提示 $1 \le n \le 10^5$ $1 \le m \le 10^9$ $1 \le a_i \le 10^4$ 感谢 @[_Wolverine](https://www.luogu.com.cn/user/120362) 提供的翻译

加入题单

算法标签: