-
Notifications
You must be signed in to change notification settings - Fork 0
/
B_Books.cpp
61 lines (53 loc) · 1.15 KB
/
B_Books.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <list>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <iostream>
#include <fstream>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
using namespace std;
int main() {
long long n, t;
cin >> n >> t;
vector<long long> books(n);
for(int i = 0; i < n; ++i) {
cin >> books[i];
}
long long nbbook = 0;
long long i = 0, j = 1;
long long sum = books[0];
if (sum <= t) nbbook++;
while(j < n) {
while (sum <= t && j < n) {
sum += books[j];
++j;
}
nbbook = max(nbbook, j - i);
sum -= books[i++];
if (i == j ) ++j;
}
cout << sum << endl;
return 0;
}