zoukankan      html  css  js  c++  java
  • 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
     
  • 相关阅读:
    C#中类与结构体的区别
    计算机快捷键
    ArcSDE简单介绍
    SQLServer存储过程
    (ArcGIS Server10.0)Windows无法启动ArcGIS Server Object Manager服务(位于本地计算机上)。错误1067
    安装arcgis10.0出现localhost上运行的许可管理器版本不正确
    地理空间数据获取(二)
    地理空间数据免费获取(一)
    angular实现对百度天气api跨域请求
    angular实现跨域
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10580504.html
Copyright © 2011-2022 走看看