Books

CodeForces - 279B

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 ai 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.

Input

The first line contains two integers n and t (1 ≤ n ≤ 105; 1 ≤ t ≤ 109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 104), where number ai shows the number of minutes that the boy needs to read the i-th book.

Output

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

Examples

Input
4 5
3 1 2 1
Output
3
Input
3 3
2 2 3
Output
1

sol:搞出前缀和,枚举左端点,二分右端点
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,Qzh[N];
int main()
{
int i,ans=;
R(n); R(m);
for(i=;i<=n;i++)
{
Qzh[i]=Qzh[i-]+read();
}
for(i=;i<=n;i++)
{
int Po=upper_bound(Qzh,Qzh+n+,Qzh[i]+m)-Qzh;
Po--;
ans=max(ans,Po-i);
}
Wl(ans);
return ;
}
/*
input
4 5
3 1 2 1
output
3
*/
 

codeforces279B的更多相关文章

随机推荐

  1. socket实现聊天功能(二)

    socket实现聊天功能(二) WebSocket协议是建立在HTTP协议之上,因此创建websocket服务时需要调用http模块的createServer方法.将生成的server作为参数传入so ...

  2. AI 循环神经网络(RNN)

    循环神经网络(Recurrent Neural Network,简称RNN),通常用于处理序列数据.正如卷积神经网络通常用于处理网格数据(例如图像)一样. 1.展开计算图 输入.输出.记忆 权值 2. ...

  3. C# 语法二 值类型引用类型

    1.值类型 2.引用类型 一 值类型 值类型存放在栈中,引用类型存放在堆中. 值类型有:数值.布尔.字符,例如:int i;bool i2;char cr='a'; 二 引用类型 大多数类型是引用类型 ...

  4. GIT 分支管理:分支管理策略、Bug分支、Feature分支

    通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息. 如果要强制禁用Fast forward模式,Git就会在merge时生成一个新的comm ...

  5. bitcoin 源码解析 - 交易 Transaction(三) - Script

    bitcoin 源码解析 - 交易 Transaction(三) - Script 之前的章节已经比较粗略的解释了在Transaction体系当中的整体运作原理.接下来的章节会对这个体系进行分解,比较 ...

  6. go陷阱

    必看的题目:https://blog.csdn.net/weiyuefei/article/details/77963810 1.关于值传递.引用传递与指针传递 当一个变量或者新值被创建时, 如果没有 ...

  7. SpringBoot日记——分布式篇

    思考:什么是分布式?什么是微服务? 一些概念:RPC-远程过程调用,某台机器想要调用另一台机器所需要的一种服务,及分布式的服务框架,比如dubbo或者SpringCloud. 铺天盖地的分布式互联网系 ...

  8. 免费的 Vue.js 入门与进阶视频教程

    这是我免费发布的高质量超清「Vue.js 入门与进阶视频教程」. 全网最好的.免费的 Vue.js 视频教程,课程基于 Vue.js 2.0,由浅入深,最后结合实际的项目进行了最棒的技术点讲解,此课程 ...

  9. Docker容器学习梳理 - 容器登陆方法梳理(attach、exec、nsenter)

    对于运行在后台的Docker容器,我们运维人员时常是有登陆进去的需求.登陆Docker容器的方式:1)使用ssh登陆容器.这种方法需要在容器中启动sshd,存在开销和攻击面增大的问题.同时也违反了Do ...

  10. poj3126 Prime Path(c语言)

    Prime Path   Description The ministers of the cabinet were quite upset by the message from the Chief ...