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的更多相关文章
随机推荐
- linux公钥和私钥生成
1. 路径 cd /root/.ssh 2. 输入命令 ssh-keygen -t rsa 按三次回车 3. 会依次生成 id_rsa 私钥和 id_rsa.pub 公钥 [root@insure ...
- Omi框架学习之旅 - 组件通讯(data通讯) 及原理说明
接着上一篇的data-*通讯,这篇写data通讯. data通讯主要为了复杂的数据通讯. 老规矩:先上demo代码, 然后提出问题, 之后解答问题, 最后源码说明. class Hello exten ...
- python里面 循环明细对比 相同人员明细,生成同一订单里面
#2018-04-16 def action_create_purc(self,cr,uid,ids,context=None): mrp_origin_obj=self.browse(cr,uid, ...
- python 知识2
零. type()函数怎么使用 type()的使用方法:type(对象)type()是接收一个对象当做参考,之后反回对象的相应类型.>>>type(1)<type 'int'& ...
- CF535E Tavas and Pashmaks 单调栈、凸包
传送门 题意:有一场比赛,$N$个人参加.每个人有两种参数$a,b$,如果存在正实数$A,B$使得$\frac{A}{a_i} + \frac{B}{b_i}$在$i=x$处取得最大值(可以有多个最大 ...
- C# SignalR 即时通信
MSDN教程:https://docs.microsoft.com/en-us/aspnet/signalr/ 个人博客:http://www.cnblogs.com/zhili/p/SignalRQ ...
- 浅谈左偏树在OI中的应用
Preface 可并堆,一个听起来很NB的数据结构,实际上比一般的堆就多了一个合并的操作. 考虑一般的堆合并时,当我们合并时只能暴力把一个堆里的元素一个一个插入另一个堆里,这样复杂度将达到\(\log ...
- [Oracle][Partition][Controlfile]Partition 操作是否和 Controlfile有关?
Partition 操作是否和 Controlfile有关? 通过实验来判断: 对比 Partition 前后的操作,看看controlfile 的dump 信息中是否有记录,结果发现没有记录在 co ...
- [Oracle]如何观察Table 的各种Lock 之间的冲突
[Oracle]如何观察Table 的各种Lock 之间的冲突 举例: Session#15 创建表: SID 15==============create table t1 (c1 number)p ...
- python语言程序设计?
1, 别说了,我还是有几分蛋疼的.女朋友..计算机..唉 2, 今天把那几个练习写完吧? 3, 这个注释有啥用最前面的?? 4, 我在学完python后必须学完C和C++并开始离散数学和线代高数等全复 ...