Skip to content

Instantly share code, notes, and snippets.

@enzerr
Created May 31, 2023 14:42
Show Gist options
  • Save enzerr/f17c7b5989f8c791c0bb7474298e292a to your computer and use it in GitHub Desktop.
Save enzerr/f17c7b5989f8c791c0bb7474298e292a 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];
int n, D;
bool check(int x){
bool rt = false;
int val = 0;
for(int i = 0; i < x; i++) val += v[i];
for(int i = x; i<n; i++){
if(val<=D) rt = true;
val += v[i] - v[i-x];
}
if(val<=D) rt = true;
return rt;
}
int32_t main(){
cin >> n >> D;
for(int i = 0; i < n; i++) cin >> v[i];
int l = 0, r = n;
while(l<=r){
int mid = (l+r)/2;
if(check(mid)) l = mid+1;
else r = mid-1;
}
cout << l-1 << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment