• codeforces279B


    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.

    Examples

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

    sol:搞出前缀和,枚举左端点,二分右端点
    #include <bits/stdc++.h>
    using namespace std;
    typedef int ll;
    inline ll read()
    {
        ll s=0;
        bool f=0;
        char ch=' ';
        while(!isdigit(ch))
        {
            f|=(ch=='-'); ch=getchar();
        }
        while(isdigit(ch))
        {
            s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
        }
        return (f)?(-s):(s);
    }
    #define R(x) x=read()
    inline void write(ll x)
    {
        if(x<0)
        {
            putchar('-'); x=-x;
        }
        if(x<10)
        {
            putchar(x+'0');    return;
        }
        write(x/10);
        putchar((x%10)+'0');
        return;
    }
    #define W(x) write(x),putchar(' ')
    #define Wl(x) write(x),putchar('
    ')
    const int N=100005;
    int n,m,Qzh[N];
    int main()
    {
        int i,ans=0;
        R(n); R(m);
        for(i=1;i<=n;i++)
        {
            Qzh[i]=Qzh[i-1]+read();
        }
        for(i=0;i<=n;i++)
        {
            int Po=upper_bound(Qzh,Qzh+n+1,Qzh[i]+m)-Qzh;
            Po--;
            ans=max(ans,Po-i);
        }
        Wl(ans);
        return 0;
    }
    /*
    input
    4 5
    3 1 2 1
    output
    3
    */
    View Code
     
  • 相关阅读:
    P4294 [WC2008]游览计划(斯坦纳树)
    CF1056E Check Transcription(SA)
    CF1391D 505(状压dp+思维)
    CF56E Domino Principle(BIT+dp)
    P3402 可持久化并查集
    可持久化平衡树
    前端网页的懒加载
    多种认证、授权模型的比较
    CSS变量(自定义属性)实践指南
    SCSS提取和懒加载
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10580504.html
Copyright © 2020-2023  润新知