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,然后维护一个区间的最大值 ...
随机推荐
- CentOS-6.4 安装 Memcached
1.准备文件 cd /usr/src 最新版下载地址 :http://code.google.com/p/memcached/downloads/list wget http://memcached. ...
- PowerDesigner导出word,PowerDesigner把表导出到word,PDM导出word文档
PowerDesigner导出word,PowerDesigner把表导出到word,PDM导出word文档 >>>>>>>>>>>& ...
- 【安全开发】IOS安全编码规范
申明:本文非笔者原创,原文转载自:https://github.com/SecurityPaper/SecurityPaper-web/blob/master/_posts/2.SDL%E8%A7%8 ...
- Linux 集群架构
集群介绍 Keepalived 配置高可用集群
- Django SimpleCMDB 项目
创建 SimpleCMDB 项目: [root@localhost ~]$ django-admin.py startproject SimpleCMDB 创建应用,收集主机信息: [root@loc ...
- The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. Make s
我出现这个问题是引用资源文件问题 helper.getView(R.id.in_pic).setBackgroundResource(item.getResourceId()); //错的helper ...
- STL——配接器(adapters)
一.配接器 <Design Patterns>一书提到23个最普及的设计模式,其中对adapter样式的定义如下:将一个class的接口转换为另一个class 的接口,使原本因接口不兼容而 ...
- linux源码编译安装php出现 cannot find -lltdl
原因: 在编辑php时添加的“–with-mcrypt”选项造成. 解决方法: 1.如果不需要mcrypt,那么编辑php时去掉该选项,然后再make.make install. 2.如果需要mcry ...
- windows7内核分析之x86&x64第二章系统调用
windows7内核分析之x86&x64第二章系统调用 2.1内核与系统调用 上节讲到进入内核五种方式 其中一种就是 系统调用 syscall/sysenter或者int 2e(在 64 位环 ...
- 微信redirect_uri 回调错误,scope权限错误
scope权限错误以及微信redirect_uri回调错误 昨天修改项目的时候,初始时,因为项目最开始使用的是第三方授权处理,拿到的用户openid是第三方账号的,所以需要将获取对方信息的代码修改.只 ...