Codeforces 279B Books
来源:互联网 发布:查看linux系统内存大小 编辑:程序博客网 时间:2024/04/30 01:19
When Valera has got some free time, he goes to the library to read some books. Today he's gott free minutes to read. That's why Valera tookn 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 ton. Valera needs ai minutes to read thei-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 numberi, 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 then-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.
The first line contains two integers n andt (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 numberai shows the number of minutes that the boy needs to read thei-th book.
Print a single integer — the maximum number of books Valera can read.
4 53 1 2 1
3
3 32 2 3
1
这是昨天晚上比赛的一个题目,要说难吧,真是不难,但是由于做完没有处理好bug,到最后也没检查出来。
#include <stdio.h>#include <string.h>#include <math.h>int a[100010];int main(){ int i,j,n,m,s,t,k; int pos,sum,max; while(scanf("%d %d",&n,&m)!=EOF) { for(i=0;i<=n-1;i++) { scanf("%d",&a[i]); } max=0; k=0; for(i=0,pos=-1,sum=0;i<=n-1;i++) { if(i!=0) { sum-=a[i-1]; } k=0; if(pos+1<i) { pos=i-1; sum=0; } for(j=pos+1;j<=n-1;j++) { if(sum+a[j]<=m) { k=1; sum+=a[j]; pos=j; }else { break; } } if((j-i)>max) { max=j-i; } if(n-i-1<=max) { break; } } printf("%d\n",max); } return 0;}
- Codeforces 279B Books
- codeforces 279 B. Books
- Codeforces 279B Books
- [Codeforces] 279B - Books
- Codeforces 279B books
- codeforces 279-B. Books(尺取)
- Codeforces 278B Books
- 【模拟】Books CodeForces 279B
- Codeforces 279B Books(dp大法好)
- CodeForces-552B - Vanya and Books
- CodeForces 552B-Vanya and Books
- 【33.33%】【codeforces 552B】Vanya and Books
- codeforces 552B Vanya and Books
- [CF 279B]Books[二分]
- Books CodeForces
- B. Books
- B. Vanya and Books(Codeforces Round #308 (Div. 2))
- CodeForces - 552B Vanya and Books (数学阶乘)水
- DX11——基本概念及初始化流程(一)
- H.264与H.265的比较
- 实习感悟
- Clob类型转换成String类型
- 跨网段组播数据转发
- Codeforces 279B Books
- Android SDK下载和更新失败的解决方法!!!
- 递归枚举全排列
- 网站的API发布
- POJ-1273-Drainage Ditches
- ubuntu 非正常启动进不了图形界面
- JAVA中如何把system.out.println里的内容写入文件
- Android学习之AndroidManifest.xml文件解析
- Java字节流与字符流的区别