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 } 
  • 相关阅读:
    Mac 终端命令使用自动补全时忽略大小写设置
    Android App专项测试
    评估产品机会
    如何快速获取ListView的打气筒对象
    js处理日期格式yyyy-MM-dd hh:mm:ss
    websocket聊天时,图片压缩处理(url或者input-file)
    canvas图片压缩,局部放大,像素处理
    vscode 右键文件或者文件夹显示菜单
    HTML5-SQLLite连接
    ie下div模拟的表格,表头表体无法对齐
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/6743555.html
Copyright © 2011-2022 走看看