Codeforces 278B Books
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#define inf 1000000000
using namespace std;
int n, t;
int a[100005];
//int dp[100005];
int main()
{
while(scanf("%d%d",&n,&t) != EOF){
a[0] = 0;
for(int i = 1; i <= n; i++){
scanf("%d",&a[i]);
a[i] += a[i - 1];
}
//memset(dp,0,sizeof(dp));
int cnt = 0;
for(int i = 0; i < n; i++){
int left = i + 1;
int right = n;
int mid = (left + right) / 2;
while(left <= right){
if(a[mid] - a[i] > t){
right = mid - 1;
}
else{
left = mid + 1;
}
mid = (left + right) / 2;
}
cnt = max(cnt, left - i);
}
printf("%d\n",cnt - 1);
}
return 0;
}
这个区间左右都是闭的,a0 是用来辅助的所以最后答案是cnt - 1
Codeforces 278B Books的更多相关文章
- CodeForces 279B Books
http://codeforces.com/problemset/problem/279/B 题意 :Valera 有很多的空闲时间,所以他决定看书,给出n本书,编号1到n,和看每本书需要的时间,他看 ...
- CodeForces 279B Books (滑动窗口)
题意:给定n本书的阅读时间,然后你从第 i 本开始阅读,问你最多能看多少本书在给定时间内. 析:就是一个滑动窗口的水题. 代码如下: #pragma comment(linker, "/ST ...
- Codeforces Round #308 (Div. 2)B. Vanya and Books 数学
B. Vanya and Books Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/pr ...
- CodeForces Round #515 Div.3 C. Books Queries
http://codeforces.com/contest/1066/problem/C You have got a shelf and want to put some books on it. ...
- 数学 Codeforces Round #308 (Div. 2) B. Vanya and Books
题目传送门 /* 水题:求总数字个数,开long long竟然莫名其妙WA了几次,也没改啥又对了:) */ #include <cstdio> #include <iostream& ...
- 【33.33%】【codeforces 552B】Vanya and Books
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- B. Vanya and Books( Codeforces Round #308 (Div. 2) 简单题)
B. Vanya and Books time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- CodeForces - 1214D B2. Books Exchange (hard version)
题目链接:http://codeforces.com/problemset/problem/1249/B2 思路:用并查集模拟链表,把关系串联起来,如果成环,则满足题意.之后再用并查集合并一个链,一个 ...
- Codeforces 279 B Books
题意:给出n本书,总的时间t,每本书的阅读时间a[i],必须按照顺序来阅读,问最多能够阅读多少本书 有点像紫书的第七章讲的那个滑动区间貌似 维护一个区间的消耗的时间小于等于t,然后维护一个区间的最大值 ...
随机推荐
- [原] unity3d调用android版 人人sdk
开发过程 遇到天坑:纯android工程没问题,集成到unity3d中 就老提示 没登陆 .最后跟到底 发现是Util.java 中 openUrl 函数出的bug.unity3d 中调android ...
- [转]Struts2多个文件上传
转载至:http://blog.csdn.net/hanxiaoshuang123/article/details/7342091 Struts2多个文件上传多个文件上传分为List集合和数组,下面我 ...
- 简单思考 如何用PHP输出本周的周三日期
简单思考 如何用PHP输出本周的周三日期?比如今天2017-10-31 计算本周周三应该是2017-11-01 自己动脑筋想一想,然后给我留言或者评论
- 【转】使程序在Linux下后台运行 (关掉终端继续让程序运行的方法)
一.为什么要使程序在后台执行 我们计算的程序都是周期很长的,通常要几个小时甚至一个星期.我们用的环境是用putty远程连接到日本Linux服务器.所以使程序在后台跑有以下三个好处: 1:我们这边是否关 ...
- 【代码审计】Cscms_v4.1 任意文件删除漏洞实例
环境搭建: CSCMS :http://www.chshcms.com/ 网站源码版本:Cscms_v4.1正式版(发布日期:2017-06-05) 程序源码下载:https://github.com ...
- iOS开发--UIButton 设置圆角 边框颜色 点击回调方法
UIButton *signBtn = [UIButton buttonWithType:UIButtonTypeCustom]; signBtn.frame = CGRectMake(, , , ) ...
- material mem
http://blog.csdn.net/caihaijiang/article/details/5903133 http://akunamotata.iteye.com/blog/1625804 刷 ...
- CharacterMotor_刚体角色驱动
using UnityEngine; //this class holds movement functions for a rigidbody character such as player, e ...
- Theme.AppCompat.Light的解决方法
style name=”AppBaseTheme” parent=”Theme.AppCompat.Light” 改为 改为 style name=”AppBaseTheme” parent=”and ...
- thinkjs+swagger Editor
一直很好奇专门写接口同事的工作,于是趁着手边工作中的闲暇时间,特地看看神奇的接口文档怎么摆弄. 总览: 这是基于thinkjs(3.0),使用swagger editor编写,实现功能性测试的接口文档 ...