zoukankan      html  css  js  c++  java
  • Books CodeForces

    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.

    Example

    Input
    4 5
    3 1 2 1
    Output
    3
    Input
    3 3
    2 2 3
    Output
    1

    1.建议学会算法,不懂尽情百度!
     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 using namespace std;
     5 
     6 int main()
     7 {  int n,m;
     8    while(~scanf("%d%d",&n,&m)){
     9          int s[n+1];
    10          for(int i=1;i<=n;i++) scanf("%d",&s[i]);
    11          int l=1,r=1;
    12          int ans=0,temp=0;
    13          while(r<=n){
    14               temp+=s[r];
    15               r++;
    16               while(temp>m){
    17                   temp-=s[l];
    18                   l++;              
    19               }
    20               ans=max(ans,r-l);   //更新答案 
    21          }
    22          cout<<ans<<endl;
    23    }
    24 } 
  • 相关阅读:
    表单
    HTML5新特性
    Bash中的特殊字符
    网站商务通链接快速标识v1.0.js
    js实现中文简繁切换效果
    input 表单点击消失离开出现
    canonical 标签介绍
    商务通对话窗口出现验证码
    织梦dedecms后台发布文章不自动更新首页与栏目列表页
    dedecms修改templets为别的名字
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/6743555.html
Copyright © 2011-2022 走看看