博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces279B
阅读量:4446 次
发布时间:2019-06-07

本文共 2272 字,大约阅读时间需要 7 分钟。

Books

 

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 
using namespace std;typedef int ll;inline ll read(){ ll s=0; bool f=0; char ch=' '; while(!isdigit(ch)) { f|=(ch=='-'); ch=getchar(); } while(isdigit(ch)) { s=(s<<3)+(s<<1)+(ch^48); ch=getchar(); } return (f)?(-s):(s);}#define R(x) x=read()inline void write(ll x){ if(x<0) { putchar('-'); x=-x; } if(x<10) { putchar(x+'0'); return; } write(x/10); putchar((x%10)+'0'); return;}#define W(x) write(x),putchar(' ')#define Wl(x) write(x),putchar('\n')const int N=100005;int n,m,Qzh[N];int main(){ int i,ans=0; R(n); R(m); for(i=1;i<=n;i++) { Qzh[i]=Qzh[i-1]+read(); } for(i=0;i<=n;i++) { int Po=upper_bound(Qzh,Qzh+n+1,Qzh[i]+m)-Qzh; Po--; ans=max(ans,Po-i); } Wl(ans); return 0;}/*input4 53 1 2 1output3*/
View Code

 

 

转载于:https://www.cnblogs.com/gaojunonly1/p/10580504.html

你可能感兴趣的文章
WCF netTcp配置
查看>>
单例类
查看>>
python 正则表达式 提取网页中标签的中文
查看>>
2015武大校赛
查看>>
LA 2531 The K-league 最大流
查看>>
我的近期学习计划
查看>>
从零开始学习前端JAVASCRIPT — 6、JavaScript基础DOM
查看>>
Edit显示行号
查看>>
取得字符串中指定的字符str[]
查看>>
delphi TOpenDialog
查看>>
vue - 子路由-路由嵌套
查看>>
static关键字用法
查看>>
JVM调优总结
查看>>
从yum提示空间不足到根分区扩容
查看>>
关于编程的思考
查看>>
20款最佳jQuery应用程序和框架(上)
查看>>
git安装和使用
查看>>
数据类型转换
查看>>
CycleGAN 各种变变变
查看>>
Nodejs学习笔记(2) 阻塞/非阻塞实例 与 Nodejs事件
查看>>