NYOJ 649 Books
来源:互联网 发布:linux vi编辑器 查找 编辑:程序博客网 时间:2024/05/21 18:07
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
- 输入
- The first line contains two integers n and t (1 ≤ n ≤ 10^5; 1 ≤ t ≤ 10^9) — 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 ≤ 10^4), where number ai shows the number of minutes that the boy needs to read the i-th book
- 输出
- Print a single integer — the maximum number of books Valera can read
- 样例输入
4 53 1 2 13 32 2 3
- 样例输出
31
题目大意就是:输入两个数,一个n(代表有n本书),一个t(代表t分钟),
然后输入n个数据 代表每本书读完所需要的时间
在t分钟之内 最多能读几本书
比较水 直接遍历就能过
#include<stdio.h>int main() { int n, m; while(scanf("%d%d", &n, &m) != EOF) { int t[100005], max = 0; for(int i = 0; i < n; i++) scanf("%d", &t[i]); for(int i = 0; i < n; i++) { int temp = m, sum = 0; for(int j = i; j < n && temp >= 0; j++) { temp -= t[j]; if(temp >= 0) sum++; } if(sum > max) max = sum; } printf("%d\n", max); }}
- NYOJ 649 Books
- books
- books
- books
- books
- Books
- books
- books
- Books
- Books
- books: reference books
- Recommended Books
- c++Books
- Python Books
- Good books
- Books List
- Hacking books
- Oracle Books
- myeclipse10安装激活
- 五步搞定Android开发环境部署——非常详细的Android开发环境搭建教程
- WinRAR 5.5 破解方法
- Java设计模式百例
- MFC DLL
- NYOJ 649 Books
- SVN服务器搭建和使用(二)
- Angular路由
- Thinker热修复
- 一起学并发编程
- Spring Cloud Bus之RabbitMQ初窥
- PHP 安装 Pthreads (解决 class Thread not found )
- Java设计模式百例
- .gitignore规则和忽略已经被git管理的文件