-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBooks.cpp
More file actions
43 lines (41 loc) · 926 Bytes
/
Books.cpp
File metadata and controls
43 lines (41 loc) · 926 Bytes
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
#include <bits/stdc++.h>
#define ll long long int
#define ls long long unsigned
using namespace std;
int main()
{
int n,t;
cin>>n>>t;
int a[n];
for(int i=0; i<n; i++)
{
cin>>a[i];
}
int sum=0;
int num=0;
int k=0;
int ans=0;
for(int i=0; i<n; i++)
{
if(a[i]<=t)
{
sum=sum+a[i];
num++;
if(sum>t)
{
while(sum>t)
{
sum=sum-a[k];
k++;
num--;
}
ans=max(ans,num);
}
else{
ans=max(ans,num);
}
}
}
cout<<ans<<endl;
return 0;
}