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. Echo团队Alpha冲刺随笔 - 第六天

    项目冲刺情况 进展 开始着手服务器部署.小程序改了几个BUG,WEB端完成接近一半,后端主体功能大致完成 问题 服务器反向代理有点问题 心得 Learning By Doing! 今日会议内容 黄少勇 ...

  2. Luogu P1082 同余方程(exgcd模版)

    传送门 求ax%b = 1,即ax - by = 1: 很明显这是一个exgcd的形式. 那么要做这道题,首先需要gcd和exgcd的算法作铺垫. gcd(辗转相膜法): int gcd(int a, ...

  3. oa tomcat 代码处理跨域问题

    meta标签处理http.https跨域 <!-- 将http请求转成https请求 --> <meta http-equiv="Content-Security-Poli ...

  4. ADO.NET的Connection Timeout和Command Timeout (转载)

    每次对数据库连接时,我们有时候会碰到连接超时或者命令超时,这两个超时是不一样的.以ADO.NET为例,当客户端和服务器端连接时,碰到的超时情况主要有下面几种:当从连接池获取一个连接时,碰到超时.当建立 ...

  5. Luogu1344 追查坏牛奶 最小割

    题目传送门 题意:给出$N$个节点$M$条边的有向图,边权为$w$,求其最小割与达到最小割的情况下割掉边数的最小值.$N \leq 32,M \leq 1000,w\leq 2 \times 10^6 ...

  6. 重装系统之无法在驱动器0的分区1上安装windows

    在通过U盘或光盘安装win8/win8.1/win10 时,遇到无法安装的问题,提示“无法在驱动器0的分区1上安装windows”,格式化分区也不能解决,进而提示Windows无法安装到这个磁盘,选中 ...

  7. Linux/CentOS下安装MySql RPM Bundle

    一.下载对应的版本的MySql安装文件 1.下载路径 https://dev.mysql.com/downloads/mysql/ 2.选择对应的Linux版本和x86/x64位的安装文件 查看Lin ...

  8. sklearn学习笔记之简单线性回归

    简单线性回归 线性回归是数据挖掘中的基础算法之一,从某种意义上来说,在学习函数的时候已经开始接触线性回归了,只不过那时候并没有涉及到误差项.线性回归的思想其实就是解一组方程,得到回归函数,不过在出现误 ...

  9. confluence上传文件附件预览乱码问题(linux服务器安装字体操作)

    在confluence上传excel文件,预览时发现乱码问题主要是因为再上传文件的时候一般是Windows下的文件上传,而预览的时候,是linux下的环境,由于linux下没有微软字体,所以预览的时候 ...

  10. linux下用户操作记录审计环境的部署记录

    通常,我们运维管理人员需要知道一台服务器上有哪些用户登录过,在服务器上执行了哪些命令,干了哪些事情,这就要求记录服务器上所用登录用户的操作信息,这对于安全维护来说很有必要.废话不多说了,下面直接记录做 ...