codeforces279B
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
4 5
3 1 2 1
3
3 3
2 2 3
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的更多相关文章
随机推荐
- rbac组件
创建新项目 新建一个项目untitled,注意django 版本为1.11 修改models.py,增加2个表 from django.db import models class Classes(m ...
- C语言的基本数据类型
代码如下: // text.cpp: 定义控制台应用程序的入口点. // #include "stdafx.h" int main() { int a; //告诉编译器,分配 4 ...
- python属性查找 深入理解(attribute lookup)
在Python中,属性查找(attribute lookup)是比较复杂的,特别是涉及到描述符descriptor的时候. 在上一文章末尾,给出了一段代码,就涉及到descriptor与attribu ...
- 高速LVDS电平简介
一.LVDS简介 1.1.LVDS信号介绍LVDS:Low Voltage Differential Signaling,低电压差分信号.LVDS传输支持速率一般在155Mbps(大约为77MHZ)以 ...
- SQL Server 中如何移动tempdb到新的位置
操作步骤:1.检查tempdb的逻辑名字和它的存在位置.可以使用下面语句: SELECT name, physical_name FROM sys.master_files WHERE databas ...
- HSF源码阅读
HSF各组成之间的关系 1 服务提供者注册与发布 <bean id="hsfTestService" class="com.test.service.impl.Hs ...
- Luogu2467 SDOI2010 地精部落 DP
传送门 一个与相对大小关系相关的$DP$ 设$f_{i,j,0/1}$表示放了$i$个,其中最后一个数字在$i$个中是第$j$大,且最后一个是极大值($1$)或极小值时($0$)的方案数.转移: $$ ...
- mac安装CocoaPods遇到的问题及解决办法
(1)sudo gem install cocoapods Fetching: i18n-0.7.0.gem (100%) Successfully installed i18n-0.7.0 Fetc ...
- Python基础(函数,函数的定义,函数的调用,函数的参数,递归函数)
1.函数 我们知道圆的面积计算公式为: S = πr2 当我们知道半径r的值时,就可以根据公式计算出面积.假设我们需要计算3个不同大小的圆的面积: r1 = 12.34 r2 = 9.08 r3 = ...
- [Spark][Python]sortByKey 例子
[Spark][Python]sortByKey 例子: [training@localhost ~]$ hdfs dfs -cat test02.txt00002 sku01000001 sku93 ...