B.Books
time limit per test: 2 seconds
每次测试的时间限制:2秒
memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节
input: standard input
输入:标准输入
output: standard output
产出:标准产出
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.Lets number the books by integers from 1
在图书馆里取了n本书,每一本书他估计他需要阅读的时间。
to n.Valera needs a; 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 numberi+2and so on.He continues the process until he either runs out of
先读第一本书,然后读第I+1本书,然后再读第i+2本书等等。
the free time orfinishes reading the n-th book. Valera reads each book up to the end,that s, he doesnt start reading the bookif he doesnt
空闲时间或读完第n本书.瓦莱拉把每本书读到最后,也就是说,如果他不读这本书,他就不会开始读这本书。
have enough free time to finish reading it.
有足够的空闲时间读完它。
Print the maximum number of books Valera can read.
打印瓦莱拉可以阅读的书籍的最大数量。
lnput
输入
The frst line contains two integers n and t(1≤n≤10’;1t≤10)一the number of books and the number of free minutes Valeras got
这一行包含两个整数n和t(1≤n,≤10‘;1t≤10)一,图书数和空闲分钟数
The second line contains a sequence of : integers aj,1p…n(1≤a;$10*’),where number aj shows the number of minutes that the
第二行包含一个序列:整数AJ,1p.n(1≤a;$10*‘),其中数字AJ表示
boy needs to read the i-th book.
男孩需要读第一本书。
output
输出量
Print a single integer -the maximum number of books Valera can read.
打印一个整数-瓦莱拉可以阅读的书籍的最大数量。
*** 双端队列,大就出队,小就入队***
int a[100001];
int main()
{
long long n, s,san=0,num=0,maxn=0,he=0;
cin >> n >> s;
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i)
{
++num;
san += a[i];
while (san > s && he <= i)
{
--num;
san -= a[he];
++he;
}
maxn = maxn > num ? maxn : num;
}
cout << maxn << endl;
}