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的更多相关文章
随机推荐
- docker被入侵后.............
服务器上线后,怎么发现总有个 xmrig 的容器在跑,删了还出来 那么恭喜你!!你的服务器已经被入侵了!! $ docker ps IMAGE COMMAND ...
- Spring Boot 之 Profile 使用
Spring Boot 之 Profile 使用 一个应用为了在不同的环境下工作,常常会有不同的配置,代码逻辑处理.Spring Boot 对此提供了简便的支持. 关键词: @Profile.spri ...
- 阿里云ECS服务器折腾记(一):小白入门遇到的各类问题
上周日折腾了一次阿里云服务器,被linux的网络问题折腾的够呛.在这里简单做个问题的概要记录,以备忘.题目中说自己是小白,其实也不完全是小白,自己对一些linux的常用命令还是有所了解的,但是对于li ...
- 截取字符串中最后一个中文词语(MS SQL)
有朋友需求一个问题,就是处理一张表中某一字段,从这个字段中去截取内容中最后一个中文词语. ID SourceText Result 1 张达:U:1杨英苹:U:1,周忱:U:1,;苗桥:U:1,章玮: ...
- virtual box问题记录
1.已存在的虚拟机打开错误,可能是版本不一样的问题,我5.2.16版本,原虚拟机所属版本为4.3.12,换回4.3.12版本virtual box即可.
- 【适配整理】Android 7.0 调取系统相机崩溃解决android.os.FileUriExposedException
一.写在前面 最近由于廖子尧忙于自己公司的事情和 OkGo (一款专注于让网络请求更简单的网络框架) ,故让LZ 接替维护 ImagePicker(一款支持单.多选.旋转和裁剪的图片选择器),也是处理 ...
- (4)学习笔记 ) ASP.NET CORE微服务 Micro-Service ---- Consul服务发现和消费
上一章说了 Consul服务注册 现在我要连接上Consul里面的服务 请求它们的API接口 应该怎么做呢? 1.找Consul要一台你需要的服务器 1.1 获取Consul下的所有注册的服务 u ...
- Android 安全退出应用程序的方法总结
正常关闭应用程序: 当应用不再使用时,通常需要关闭应用,可以使用以下三种方法关闭android应用: 第一种方法:首先获取当前进程的id,然后杀死该进程. android.os.Process.kil ...
- Mysql读写分离方案-MySQL Proxy环境部署记录
Mysql的读写分离可以使用MySQL Proxy和Amoeba实现,其实也可以使用MySQL-MMM实现读写分离的自动切换.MySQL Proxy有一项强大功能是实现"读写分离" ...
- 查看服务器系统资源(cpu,内容)利用率前几位的进程的方法
在日常运维工作中,我们经常需要了解服务器上的系统资源的使用情况,要清楚知道一些重要进程所占的资源比例.这就需要熟练掌握下面几个命令的使用: 1)查看占用CPU最高的5个进程 # ps aux | so ...