Thursday, July 17, 2014

Codeforces Round #171 (Div. 2), problem: (B) Books solution

Codeforces Round #171 (Div. 2), problem: (B) Books: http://codeforces.com/problemset/problem/279/B

Codeforces Round #171 (Div. 2), problem: (B) Books editorial in russian: http://codeforces.com/blog/entry/6864

Codeforces Round #171 (Div. 2), problem: (B) Books announcement page, (i think there you can find discussions related to solutions): http://codeforces.com/blog/entry/6856

Codeforces Round #171 (Div. 2), problem: (B) Books solution: http://ideone.com/LtR47Z


#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int n, t, a[100005], ma=0, l=0, cnt=0;
    scanf("%d%d", &n, &t);
    for(int i=0; i<n; i++) {
        scanf("%d", &a[i]);
        while(t<a[i]) t+=a[l], l++, cnt--;
        t-=a[i], cnt++;
        if(cnt>ma) ma=cnt;
    }
    printf("%d", ma);
    return 0;
}

note: update left-hand side if sum current substring does not fit into "t"

No comments:

Post a Comment