B.Books

B.Books

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值