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. vue 如何在循环中绑定v-model

    vue 如何在循环中绑定v-model 我现在有这么一个需求,页面上有多项输入框,但是具体有多少项,我也不知道,它是通过"新增一项"按钮点击事件,点击一下,就新增一项:如下图这个样 ...

  2. Objective-C 浅拷贝与深拷贝

    一个Objective-C对象通常分配在堆上,并有一个或者多个指针指向它.如下代码及其关系图所示: NSObject *obj1 = [[NSObject alloc] init]; NSObject ...

  3. Objective-C 锁

    多线程在Objective-C项目中占有很大的比重,它能提高程序的运行效率,但也因此带来线程安全问题.而锁就是解决线程安全问题最常用的武器. 锁有很多种. 1.NSLock,非递归锁 NSLock * ...

  4. Android学习之触点事件的处理

    知识点: 1. Android开发中的运动事件:触摸屏(TouchScreen)和滚动球(TrackBall) 2.对运动事件的处理:MotionEvent 3.触摸时必发的三个MotionEvent ...

  5. Android 解决启动页白屏或者黑屏的问题

    欢迎页启动的线程由于请求和处理的数据量过大而,导致欢迎页在出现之前界面上会有一个短暂的白色闪屏停留,当然白色闪屏的停留是因为 application 的主题样式android:theme=@style ...

  6. Unable to execute dex: Multiple dex files defineLcom/google/gson/JsonDeserializer;

    这是异常想必大家都知道的,是关于一个android jar包冲突的问题.为什么还要提呢,是因为这玩意真心让人蛋疼.有些时候稍微不注意(手贱)多导入一个包,就完蛋了.(jar包多的话搞不好带一上午调试) ...

  7. Android ExpandableListView和ScrollView联用的一些注意事项

    之前有整理过ScrollView嵌套ListView的例子,讲的是计算listview的每一项的高度.已达到目标效果.同样的ExpandableListView嵌套ScrollView也是这么个思路, ...

  8. WireShark抓包工具使用

    WireShark是一款网络封包分析软件,它抓取网络封包,并尽可能显示出最详细的封包资料. wireshark的准备工作 安装wireshark sudo apt-get install wiresh ...

  9. linux中yum与rpm区别

    一.源代码形式 1.      绝大多数开源软件都是直接以原码形式发布的 2.      源代码一般会被打成.tar.gz的归档压缩文件 3.      源代码需要编译成为二进制形式之后才能够运行使用 ...

  10. [Oracle]快速构造大量数据的方法

    [Oracle]快速构造大量数据的方法: create table tab001(id integer primary key, val varchar2(100)); insert into tab ...