/Danoninho2.cpp Secret
Created
May 31, 2023 14:42
Revisions
-
enzerr created this gist
May 31, 2023 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ #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'; }