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的更多相关文章
随机推荐
- NodeJS之path模块
NodeJS之path模块 常用的主要有如下工具函数: 1. path.basename(path[, ext]) 2. path.extname(path) 3. path.dirname(path ...
- socket实现聊天功能(二)
socket实现聊天功能(二) WebSocket协议是建立在HTTP协议之上,因此创建websocket服务时需要调用http模块的createServer方法.将生成的server作为参数传入so ...
- appbar导航
import 'package:flutter/material.dart';import 'dart:ui'; void main()=>runApp(MyApp()); class MyAp ...
- 学习CSS布局 - margin: auto;
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- TCP/IP与OSI模型
- c语言程序设计 第一例子
#include <studio.h> int main(){ printf("this is dog.\n"); return 0; } studio.h 表示st ...
- CF 958E2. Guard Duty (medium)
这道题是昨天linkfqy dalao上课讲的一道题 当时他讲的时候就想到了一种玄学的搞法,然后不敢相信自己切掉了 没想到后来CHJ dalao也想到了这种算法,然后发现是对的 后来10min就切掉了 ...
- WPF制作带明细的环形图表
效果 明细用Popup实现的,录gif时,Popup显示不出来,不知道为什么,所以静态图凑合看吧 大体思路 图表使用Arc+Popup实现 图表分为两部分,一是环形部分,一是标注的明细部分. 环形部分 ...
- 解决项目无法添加VBIDE问题
为了方便大家引用,我直接把写好的文件放上来,方便大家下载.要注意的是:解压后需要把文件 VBIDE.DLL放入系统的(如果你的系统是32位,那就是 C:\windows\system32\..) 目录 ...
- apacheTomcat
Window+R ------>cmd || Window PowerShell apacheTomcat\bin> ./startup.sh