Submission #172734

#TimeUsernameProblemLanguageResultExecution timeMemory
172734LinusTorvaldsFanBigger segments (IZhO19_segments)C++14
13 / 100
3 ms396 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; signed main() { int n; cin>>n; vector<ll>a(n); for(int i=0;i<n;i++){ cin>>a[i]; } int ind=0; ll p_sum=0; int ans=0; while(ind<n){ ll sum=0; ll best_sum=1e18; int best_ind=-1; ll best_choice=0; for(int i=ind;i<n;i++){ sum+=a[i]; if(sum<p_sum)continue; ll cur=0; for(int j=i+1;j<n;j++){ cur+=a[j]; if(cur>=sum){ if(cur<best_sum){ best_sum=cur; best_ind=i; best_choice=sum; } } } } ans++; //cout<<best_ind<<endl; if(best_ind==-1)break; p_sum=best_choice; //cout<<best_choice<<endl; ind=best_ind+1; } cout<<ans; return 0; }
#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...