Skip to content

Instantly share code, notes, and snippets.

@enzerr
Created May 31, 2023 14:37
Show Gist options
  • Save enzerr/0ad55a36323cf73af8daf98e00b2130b to your computer and use it in GitHub Desktop.
Save enzerr/0ad55a36323cf73af8daf98e00b2130b to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e5 + 5;
int v[maxn];
int32_t main(){
int n, D; cin >> n >> D;
for(int i = 0; i < n; i++) cin >> v[i];
int l = 0, r = 0, val = v[0], ans = 0;
while(r<n){
if(val<=D) ans=max(ans, r-l+1), r++, val+=v[r];
else val-=v[l], l++;
}
cout << ans << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment