Codeforces 279B Books

#include<bits/stdc++.h>
using namespace std;
int a[100020];
int main()
{
    int n,t;
    scanf("%d%d",&n,&t);
    int sum=0,k=1,Max=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
        while(sum>t)
        {
            sum-=a[k];
            k++;
        }
        if(i-k+1>Max)
            Max=i-k+1;
    }
    printf("%d\n",Max);
    return 0;
}

时间: 2024-10-08 17:49:23

Codeforces 279B Books的相关文章

CodeForces 279B Books (滑动窗口)

题意:给定n本书的阅读时间,然后你从第 i 本开始阅读,问你最多能看多少本书在给定时间内. 析:就是一个滑动窗口的水题. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream>

codeforces - 1249B2 Books Exchange (hard version)

https://vjudge.net/problem/CodeForces-1249B2 题目描述: The only difference between easy and hard versions is constraints. There are nn kids, each of them is reading a unique book. At the end of any day, the ii-th kid will give his book to the pipi-th kid

Books

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 279B Description 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. Tha

数学 Codeforces Round #308 (Div. 2) B. Vanya and Books

题目传送门 1 /* 2 水题:求总数字个数,开long long竟然莫名其妙WA了几次,也没改啥又对了:) 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 #include <vector> 10 #include <string> 11 #inc

Codeforces 279 B Books

题意:给出n本书,总的时间t,每本书的阅读时间a[i],必须按照顺序来阅读,问最多能够阅读多少本书 有点像紫书的第七章讲的那个滑动区间貌似 维护一个区间的消耗的时间小于等于t,然后维护一个区间的最大值 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<vector> 7

Books Queries (codeforces 1066C)

模拟题 开一个容器进行模拟即可,注意容器设置初始大小不然容易re.设置两个指针l,r.把容器当作桶,每一个桶都有一个编号表示位置,左边进入那么就是编号为l,右边一样.然后l--或者r++,l=r=0的初始值,第一个元素为0,然后同时l--,r++ 代码(cf上的题解) #include <bits/stdc++.h> using namespace std; main() { int n; cin>>n; deque<int> vec(300000); int l=0;

codeforces 500C New Year Book Reading (贪心,很好的思维题)

C. New Year Book Reading time limit per test 2 seconds memory limit per test 256 megabytes New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-

Codeforces Round #308 (Div. 2)

A. Vanya and Table Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose n rect

CodeForces 215B Olympic Medal(数学啊)

题目链接:http://codeforces.com/problemset/problem/215/B Description The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of r1 cm, inner radius of r2 cm, (0?<?r2?<?r1) made of metal wi