/Danoninho2.cpp Secret
Created
May 31, 2023 14:42
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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