Submission #524612

#TimeUsernameProblemLanguageResultExecution timeMemory
524612DragonO_oBigger segments (IZhO19_segments)C++17
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; #define x first #define y second #define pb push_back #define all(a) a.begin(),a.end() #define int long long typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int,int>pii; typedef pair<ll,ll>pll; typedef vector<ll>vll; typedef vector<int>vi; typedef vector<bool>vb; typedef vector<vi>vvi; typedef vector<vll>vvll; typedef vector<pii>vpii; typedef vector<pll>vpll; const int N=5e5+99; int a[N],pref[N]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; for(int i=1;i<=n;++i){ cin>>a[i]; pref[i]=pref[i-1]+a[i]; } int l=1,r=n,ans=-1; while(l<r){ int mid=(l+r)/2; int cur=mid+1,prev=pref[mid],cnt=1; while(cur<=n){ int sum=0; for(int i=cur;i<=n;++i){ sum+=a[i]; if(sum>=prev){ prev=sum; cnt++; cur=i+1; break; } } if(sum<prev){ break; } } ans=max(ans,cnt); if(cnt==-1){ l=mid+1; } else{ r=mid; } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...