Books CodeForces
来源:互联网 发布:美工包括哪些 编辑:程序博客网 时间:2024/05/16 17:36
Books CodeForces - 279B
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.
/*求连续最长的数目*/#include <cstdio> #include<iostream> #include <cmath> using namespace std; int a[100005];int main(){ int n,t,i,pos=0,sum=0,k=0,mx=0; cin>>n>>t; for(i=0;i<n;i++) cin>>a[i]; for(i=0;i<n;i++){ sum+=a[i]; while(sum>t){ sum-=a[pos]; pos++; } if(k<=i-pos+1) k=i-pos+1; } cout<<k<<endl; return 0;}
- Books CodeForces
- Codeforces 279B Books
- codeforces 279 B. Books
- Codeforces 279B Books
- [Codeforces] 279B - Books
- Codeforces 279B books
- Codeforces 278B Books
- CodeForces-552B - Vanya and Books
- CodeForces 552B-Vanya and Books
- 【33.33%】【codeforces 552B】Vanya and Books
- codeforces 279-B. Books(尺取)
- codeforces 552B Vanya and Books
- [Codeforces 877F] Ann and Books
- books
- books
- books
- books
- Books
- freemarker之快速入门(一)
- 解决 Sublime text3 中文显示乱码问题
- git pull和git pull -- rebase
- 调用EntityManager出现The import javax.persistence cannot be resolved
- 配置文件保存在exe所在目录
- Books CodeForces
- Redis常用命令之排序函数
- flask使用Blueprint进行多模块应用的编写
- 邻接表(c语言)
- 基于Hexo搭建博客
- 错误解决】The prefix "context" for element "context:component
- How does Android-x86 work? --- Chih-Wei Huang answer the problem.
- Struts2_自定义转换器
- 读《大话设计模式》学习小结(一)装饰器模式